2017-11-28 9 views
0

自分のアカウントケースを作成したいと思います。ユーザーとセッションを作成してテストに使用します。私はConnCaseを見て、そうしよう:テストファイルでExUnit独自のケース

defmodule MyAppWeb.AccountHelpers do 
    using(opts) do 
    user_attrs = Keyword.get(opts, :attrs, %{login: "[email protected]", password: "123456", locale: "en"}) 
    quote do 
     def fixture(:user) do 
     {:ok, %{session: session, user: user}} = MyApp.Sessions.register_user(user_attrs) 
     .... 
     {:ok, %{user: user, session: session}} 
     end 
    end 
    end 
end 

、私はそうする:

defmodule MyAppWeb.V1.CategoryControllerTest do 
    use MyAppWeb.ConnCase 
    use MyAppWeb.AccountHelpers 
... 
end 

が、私は、テストを実行すると、私は

** (CompileError) test/myapp_web/controllers/v1/category_controller_test.exs:3: module MyAppWeb.AccountHelpers is not loaded and could not be found 
    (elixir) expanding macro: Kernel.use/1 
エラーが出ます

ケースを正しく作成するにはどうすればよいですか?フェニックスのtest環境で

+0

どのファイルに 'MyAppWeb.AccountHelpers'が定義されていますか? – Dogbert

+0

../myapp/test/account_helpers.ex –

+0

私は../myapp/test/support/に移動しました。ありがとう! @Dogbert –

答えて

1

、あなたのテストでのみ.exコンパイルされたファイル、したがって、利用可能.exsファイルがlib/test/support/中のもの(あなたのmix.exselixirc_pathsの定義を参照)です。 .exファイルはtest/にあり、コンパイルされません。つまり、そこに定義されているモジュールはテストで使用できず、「見つかりませんでした」というエラーが表示されます。解決策は.exファイルをtest/support/に移動することです。

関連する問題