简体   繁体   English

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

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

How can I make Mix run only specific tests from my suite of tests?如何让 Mix 仅运行我的测试套件中的特定测试?

When running mix test all tests are executed运行mix test时执行所有测试

There are 5 ways to run only specific tests with Elixir有 5 种方法可以使用 Elixir 仅运行特定测试

  1. run a single file with mix test path_to_your_tests/your_test_file.exs使用mix test path_to_your_tests/your_test_file.exs运行单个文件
    This will run all test defined in your_test_file.exs这将运行your_test_file.exs定义的所有测试

  2. run a specific test from a specific test file by adding a colon and the line number of that test通过添加冒号和该测试的行号,从特定测试文件运行特定测试
    for example mix test path_to_your_tests/your_test_file.exs:12 will run the test at line 12 of your_test_file.exs例如mix test path_to_your_tests/your_test_file.exs:12将在your_test_file.exs第 12 行运行测试

  3. define a tag to exclude on your test methods定义要在测试方法中排除的标签

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

    on the command line execute your tests like this在命令行上像这样执行你的测试
    mix test --exclude disabled

  4. define a tag to include on your test methods定义要包含在测试方法中的标签

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

    on the command line execute your tests like this在命令行上像这样执行你的测试
    mix test --only mustexec

  5. Generally exclude some tagged tests by adding this to your test/test_helper.exs file通常通过将其添加到您的test/test_helper.exs文件来排除一些标记的测试
    ExUnit.configure exclude: [disabled: true]

Warning: Mix has an --include directive.警告: Mix 有一个--include指令。 This directive is NOT the same as the --only directive.这个指令是一样的--only指令。 Include is used to break the general configuration (exclusion) from the test/test_helper.exs file described under 4). Include 用于从 4) 中描述的test/test_helper.exs文件中打破常规配置(排除)。

For some reason googling for elixir mix include tests or the like never shows up on my search results therefore I have written this entry and its answer.出于某种原因,在我的搜索结果中搜索elixir mix include tests等从未出现过,因此我写了这个条目及其答案。 For more info, see the Mix documentation .有关详细信息,请参阅Mix 文档

If you don't want mix test to run certain test files, just rename them.如果您不想让mix test运行某些测试文件,只需重命名它们即可。 mix test matches on any file ending with _test.ex or _test.exs so all you have to do is rename those files that you don't want to run to something else that does not match, like _test_off.ex .在任何以_test.ex_test.exs结尾的文件上mix test匹配,因此您所要做的就是将那些您不想运行的文件重命名为其他不匹配的文件,例如_test_off.ex

controller_test.exs -> controller_test_off.exs controller_test.exs -> controller_test_off.exs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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