Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable a Googletest (gtest) parametrized test?

Tags:

c++

googletest

Googletest (GTest) allows you to disable individual tests by adding

DISABLED_

prefix to the test name.

What about parametrized tests -- how do I disable those? Adding the prefix to the test name does not disable them.

For example, how do I disable the example test provided by GTest documentation:

class FooTest : public ::testing::TestWithParam<const char*> {
  // You can implement all the usual fixture class members here.
  // To access the test parameter, call GetParam() from class
  // TestWithParam<T>.
};

TEST_P(FooTest, HasBlahBlah) {
  ...
}

INSTANTIATE_TEST_CASE_P(InstantiationName,
                        FooTest,
                        ::testing::Values("meeny", "miny", "moe"));
like image 309
Victor Lyuboslavsky Avatar asked Mar 26 '13 20:03

Victor Lyuboslavsky


People also ask

How do I turn off test Gtest?

The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0 , as disabled tests are still compiled (and thus won't rot).

How do I disable test suite?

If you need one or more test suites to be skipped during a project run, you can disable them. To do this: Right-click the desired test suites and select Disable Test Suite.

What is Instantiate_test_case_p?

INSTANTIATE_TEST_CASE_P( LeapYearTests, LeapYearParameterizedTestFixture, ::testing::Values( 1, 711, 1989, 2013 )); Here we call the INSTANTIATE_TEST_CASE_P macro with first with a unique name for the instantiation of the test suite. This name can distinguish between multiple instantiations.

What is Test_p?

TEST_P() is useful when you want to write tests with a parameter. Instead of writing multiple tests with different values of the parameter, you can write one test using TEST_P() which uses GetParam() and can be instantiated using INSTANTIATE_TEST_SUITE_P() . Example test. Follow this answer to receive notifications.


1 Answers

You need to add the

DISABLED_

prefix to the instantiation name, like this:

INSTANTIATE_TEST_CASE_P(DISABLED_InstantiationName,
                        FooTest,
                        ::testing::Values("meeny", "miny", "moe"));
like image 72
Victor Lyuboslavsky Avatar answered Oct 17 '22 21:10

Victor Lyuboslavsky