13

Can I run test cases based on "not matching" a particular tag in 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);
}

I want to invoke testcases that are not falling in [NotWorking] tag until I finish implementing that functionality.

schorsch312
  • 5,553
  • 5
  • 28
  • 57
Wander3r
  • 1,801
  • 17
  • 27

2 Answers2

10

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

Test case examples:

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

So in your case add to the command line:

exclude:NotWorking

or

~NotWorking
Robert Andrzejuk
  • 5,076
  • 2
  • 22
  • 31
  • 4
    Actually, to use tags you need to use square-brackets, ie. `~[NotWorking]`. Catch2 has the magic [!mayfail](https://github.com/catchorg/Catch2/blob/devel/docs/test-cases-and-sections.md#special-tags) tag which will not fail when there are failures in that section. – Bklyn Oct 20 '21 at 17:53
2

For your usecase of including the test, but expecting some assertions to fail you would be better off with the [!mayfail] tag.

See here:

[!mayfail] - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in your tests.

Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46