2016-09-29 54 views
2

我爲我的Elixir項目編寫了一些測試,並將它們放在test/目錄中。現在,我跑mix test,我得到:混合測試 - 測試模式不匹配任何文件

$ mix test 
Test patterns did not match any file: 

就是這樣,以後什麼都沒有。 我是否必須手動設置我的測試路徑? Google快速搜索沒有發現任何內容。


這是我所有的測試看起來像:

# project_dir/test/my_app/some_module.exs 

defmodule MyApp.SomeModule.Test do 
    use ExUnit.Case 
    doctest MyApp.SomeModule 

    test "method 1" do 
    assert MyApp.SomeModule.method_1_works? 
    end 

    test "method 2" do 
    assert MyApp.SomeModule.method_2_works? 
    end 
end 

回答

4

所有的測試都應該與_test.exs結束。將我的測試從some_module.exs重命名爲some_module_test.exs修復它,現在它工作。

$ mix help test

此任務將啓動當前的應用程序,加載了 test/test_helper.exs,然後需要匹配並行 test/**/_test.exs模式的所有文件。


我還是想知道它是否可以手動配置測試路徑(即使這個詞「測試」不以結束)。

+1

是的,這是可能的 - 運行'混合幫助測試'並參見塊配置。 ':test_paths' - 包含測試文件的路徑列表,默認爲 '[「test」]'。預計所有測試路徑都包含一個'test_helper.exs'文件。 ':test_pattern' - 加載測試文件的模式,默認爲'* _test.exs'。 –

+1

是否有原因要改變測試路徑而不是使用默認值?運行'混合新'應該給你一個好腳手架。除非有一個令人信服的理由,爲什麼您需要讓文件不以* _test.exs結尾,我認爲最好保持默認值。保持它的慣用和所有 – Kevin

相關問題