如何运行:来自命令行的挂起测试?

ken*_*riu 3 unit-testing elixir

我有时会看到测试被评为 :pending

ExUnit.start
ExUnit.configure(exclude: :pending)

defmodule SublistTest do
  use ExUnit.Case, async: true

  test "empty equals empty" do
    assert Sublist.compare([], []) == :equal
  end

  @tag :pending
  test "empty is a sublist of anything" do
    assert Sublist.compare([], [nil]) == :sublist
  end
end
Run Code Online (Sandbox Code Playgroud)

当你从shell运行测试时,显然会从执行中排除

elixir sublist_test.exs
Run Code Online (Sandbox Code Playgroud)

有没有办法在:pending命令行运行测试时包含测试?

第二个问题:为什么人们将测试标记为:pending.

Pat*_*ity 5

您可以mix test使用Mix项目中的任务执行此操作.混合项目设置起来非常简单:

$ mix new sublist
Run Code Online (Sandbox Code Playgroud)

您可以在test/test_helper.exs以下位置指定默认排除项:

ExUnit.start()
ExUnit.configure(exclude: :pending)
Run Code Online (Sandbox Code Playgroud)

然后你可以写你的考试test/sublist_test.exs.要运行测试,请执行

$ mix test
Run Code Online (Sandbox Code Playgroud)

并包括待定测试

$ mix test --include pending
Run Code Online (Sandbox Code Playgroud)

现在提出第二个问题:人们通常将测试标记为待定,因为它们尚未实现,但他们不想忘记它们.例如,您可能处于紧迫的截止日期,但希望确保最终完成测试.或许测试还没有成功,因为你需要先实现其他的东西.

如果默认情况下不排除测试,他们会传达错误信息:受影响的测试是红色的.但他们宁愿做项目而不是实际测试,所以他们不应该默认失败.