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

标签 elixir

如何让 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将在第 12 行运行测试your_test_file.exs
  • 定义要在测试方法中排除的标签
    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 用于打破 test/test_helper.exs 中的一般配置(排除) 4)中描述的文件。

    出于某种原因,谷歌搜索 elixir mix include tests或类似内容从未出现在我的搜索结果中,因此我编写了此条目及其答案。欲了解更多信息,请参阅 the Mix documentation .

    关于elixir - 如何让 Mix 只运行我的测试套件中的特定测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26150146/

    相关文章:

    postgresql - 如何通过 ecto 将从 STR 返回的集合检索到模型中?

    hex - Elixir mix 自动确认

    elixir - 使用 Elixir/Phoenix (0.10.0),如何根据版本中的 PORT 环境变量设置端口?

    elixir - 在 Phoenix 中使用 Ecto 获取数据时仅获取特定字段

    elixir - 在 Elixir 中运行时从主 pipe 项列表中添加/删除子项

    elixir - 你在 Phoenix/Elixir 中存储 secret 的位置以及推荐的位置?

    erlang - 你如何处理 Elixir 中的 base64 编码文件?

    elixir - 从二进制文件中获取位

    postgresql - 寻找下一个生日来庆祝

    elixir - 如何在包含的模块中获取调用方模块名称?