2016-09-29 53 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

相关问题