繁体   English   中英

如何让 Mix 仅运行我的测试套件中的特定测试?

[英]How can I make Mix run only specific tests from my suite of tests?

如何让 Mix 仅运行我的测试套件中的特定测试?

运行mix test时执行所有测试

有 5 种方法可以使用 Elixir 仅运行特定测试

  1. 使用mix test path_to_your_tests/your_test_file.exs运行单个文件
    这将运行your_test_file.exs定义的所有测试

  2. 通过添加冒号和该测试的行号,从特定测试文件运行特定测试
    例如mix test path_to_your_tests/your_test_file.exs:12将在your_test_file.exs第 12 行运行测试

  3. 定义要在测试方法中排除的标签

    defmodule MyTests do @tag disabled: true test "some test" do #testtesttest end end

    在命令行上像这样执行你的测试
    mix test --exclude disabled

  4. 定义要包含在测试方法中的标签

    defmodule MyTests do @tag mustexec: true test "some test" do #testtesttest end end

    在命令行上像这样执行你的测试
    mix test --only mustexec

  5. 通常通过将其添加到您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM