如何使Mix只运行我的测试套件中的特定测试?

时间:2014-10-01 20:36:09

标签: elixir

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

运行mix test时执行所有测试

1 个答案:

答案 0 :(得分:61)

使用Elixir

只有5种方法可以运行特定的测试
  1. 使用mix test path_to_your_tests/your_test_file.exs运行单个文件 这将运行your_test_file.exs

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

  4. 定义要在测试方法中排除的标记

    defmodule MyTests do
        @tag disabled: true
        test "some test" do
            #testtesttest
        end
    end
    
    命令行上的

    执行这样的测试 mix test --exclude disabled

  5. 定义要包含在测试方法上的标记

    defmodule MyTests do
        @tag mustexec: true
        test "some test" do
            #testtesttest
        end
    end
    
    命令行上的

    执行这样的测试 mix test --only mustexec

  6. 通常会将一些标记的测试添加到您的test/test_helper.exs文件中 ExUnit.configure exclude: [disabled: true]

  7. 警告: Mix有--include指令。该指令 NOT --only指令相同。 Include用于中断4)中描述的test/test_helper.exs文件的常规配置(排除)。

    由于某些原因,我在搜索结果中显示了elixir mix include tests之类的Google搜索,因此我写了这个条目及其答案。文档可以在这里找到 http://elixir-lang.org/docs/stable/mix/