ExUnitで自動的にテストを行い、iexでinteractivlyテストするプロジェクトを作成しています。ExUnitとiexでフィクスチャとtesthelp関数を利用できるようにする
[[email protected] sample]$ tree
.
├── config
│ └── config.exs
├── fixtures
│ └── complex_struct.exs
├── lib
│ └── the_function.ex
├── mix.exs
├── README.md
└── test
└── the_test.exs
4 directories, 7 files
[[email protected] sample]$ cat lib/the_function.ex
defmodule TheFunction do
def the_function ({a, b, c}) do
a/b + c
end
end
[[email protected] sample]$ cat fixtures/complex_struct.exs
defmodule ComplexStruct do
def complex_struct do
{2, 1, 1}
end
end
[[email protected] sample]$ cat test/the_test.exs
defmodule IexandtestTest do
Code.load_file("fixtures/complex_struct.exs")
use ExUnit.Case
doctest Iexandtest
test "the test" do
assert (TheFunction.the_function (ComplexStruct.complex_struct())) == 3
end
end
私は今、ミックス・テストを実行することができますし、テストが正常に実行されるように、それは備品/ complex_struct.exsがあります:私のプロジェクトは、次のようになり言います。私はまた、次のコマンド
iex -S mix
私はlibに/ the_function.exへのアクセス権を持っているし、それをデバッグすることができますこの方法を使用して自分のコードをデバッグしたいです。
iex(1)> TheFunction.the_function({1,2,3})
3.5
しかし、私はこのようにそれをロードしない限り、私は備品/ complex_struct.exsへのアクセス全くない:
iex(1)> TheFunction.the_function(ComplexStruct.complex_struct())
** (UndefinedFunctionError) undefined function ComplexStruct.complex_struct/0 (module ComplexStruct is not available)
ComplexStruct.complex_struct()
iex(1)> Code.load_file("fixtures/complex_struct.exs")
[{ComplexStruct,
<<70, 79, 82, 49, 0, 0, 5, 28, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 137, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, 100, 0, ...>>}]
iex(2)> TheFunction.the_function(ComplexStruct.complex_struct())
3.0
IEXによってロードされますかを決定し、どのように私はすべてのモジュールlibに、すべてのことができますどのような私がiex-mixを実行するときに使用可能な備品?