[英]How can I make Mix run only specific tests from my suite of tests?
如何让 Mix 仅运行我的测试套件中的特定测试?
运行mix test
时执行所有测试
有 5 种方法可以使用 Elixir 仅运行特定测试
使用mix test path_to_your_tests/your_test_file.exs
运行单个文件
这将运行your_test_file.exs
定义的所有测试
通过添加冒号和该测试的行号,从特定测试文件运行特定测试
例如mix test path_to_your_tests/your_test_file.exs:12
将在your_test_file.exs
第 12 行运行测试
定义要在测试方法中排除的标签
defmodule MyTests do @tag disabled: true test "some test" do #testtesttest end end
在命令行上像这样执行你的测试mix test --exclude disabled
定义要包含在测试方法中的标签
defmodule MyTests do @tag mustexec: true test "some test" do #testtesttest end end
在命令行上像这样执行你的测试mix test --only mustexec
通常通过将其添加到您的test/test_helper.exs
文件来排除一些标记的测试ExUnit.configure exclude: [disabled: true]
警告: Mix 有一个--include
指令。 这个指令是不一样的--only
指令。 Include 用于从 4) 中描述的test/test_helper.exs
文件中打破常规配置(排除)。
出于某种原因,在我的搜索结果中搜索elixir mix include tests
等从未出现过,因此我写了这个条目及其答案。 有关详细信息,请参阅Mix 文档。
如果您不想让mix test
运行某些测试文件,只需重命名它们即可。 在任何以_test.ex
或_test.exs
结尾的文件上mix test
匹配,因此您所要做的就是将那些您不想运行的文件重命名为其他不匹配的文件,例如_test_off.ex
。
controller_test.exs
-> controller_test_off.exs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.