运行单元测试,但不包括Catch2中的特定标签

Wan*_*r3r 5 c++ catch2

我可以基于“不匹配” Catch2中的特定标签来运行测试用例吗?

TEST_CASE("Check the data validity","[Working]"){
  REQUIRE(true);
}

TEST_CASE("Check the input","[InProgress]"){
  REQUIRE(true);
}
TEST_CASE("Validate the response","[NotWorking]"){
  REQUIRE(false);
}
Run Code Online (Sandbox Code Playgroud)

[NotWorking]完成实现该功能之前,我想调用不属于标签的测试用例。

Rob*_*juk 6

来源:https : //github.com/catchorg/Catch2/blob/master/docs/command-line.md#specifying-which-tests-to-run

测试用例示例:

thisTestOnly            Matches the test case called, 'thisTestOnly'
"this test only"        Matches the test case called, 'this test only'
these*                  Matches all cases starting with 'these'
exclude:notThis         Matches all tests except, 'notThis'
~notThis                Matches all tests except, 'notThis'
~*private*              Matches all tests except those that contain 'private'
a* ~ab* abc             Matches all tests that start with 'a', except those that
                        start with 'ab', except 'abc', which is included
Run Code Online (Sandbox Code Playgroud)

所以在你的情况下添加到命令行:

exclude:NotWorking
Run Code Online (Sandbox Code Playgroud)

或者

~NotWorking
Run Code Online (Sandbox Code Playgroud)

  • 实际上,要使用标签,您需要使用方括号,即。`~[不工作]`。Catch2 有神奇的 [!mayfail](https://github.com/catchorg/Catch2/blob/devel/docs/test-cases-and-sections.md#special-tags) 标签,当出现故障时它不会失败在那个部分。 (4认同)