Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run specific test cases in GoogleTest

People also ask

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 Google test suite?

The Google Home Test Suite is a web application that allows you to self-test your smart home Action. The Test Suite automatically generates and runs test cases based on the devices and traits associated with your account.

How do I name a Google test?

Both arguments TestFixtureName and TestName must be valid C++ identifiers and must not contain underscores ( _ ). TestFixtureName must be the name of a test fixture class—see Test Fixtures. The statements within the test body can be any code under test.

How does Google test work?

Independent and Repeatable: Googletest isolates the tests by running each of them on a different object. Portable and Reusable: Googletest works on different Oses (Linux, Windows, or a Mac), with different compilers. When tests fail, it should provide as much information about the problem as possible.


You could use advanced options to run Google tests.

To run only some unit tests you could use --gtest_filter=Test_Cases1* command line option with value that accepts the * and ? wildcards for matching with multiple tests. I think it will solve your problem.

UPD:

Well, the question was how to run specific test cases. Integration of gtest with your GUI is another thing, which I can't really comment, because you didn't provide details of your approach. However I believe the following approach might be a good start:

  1. Get all testcases by running tests with --gtest_list_tests
  2. Parse this data into your GUI
  3. Select test cases you want ro run
  4. Run test executable with option --gtest_filter

Summarising Rasmi Ranjan Nayak's and nogard's answers and adding another option:

On the console

You should use the flag --gtest_filter, like

--gtest_filter=Test_Cases1*

(You can also do this in Properties|Configuration Properties|Debugging|Command Arguments)

On the environment

You should set the variable GTEST_FILTER like

export GTEST_FILTER = "Test_Cases1*"

On the code

You should set a flag filter, like

::testing::GTEST_FLAG(filter) = "Test_Cases1*";

such that your main function becomes something like

int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::GTEST_FLAG(filter) = "Test_Cases1*";
    return RUN_ALL_TESTS();
}

See section Running a Subset of the Tests for more info on the syntax of the string you can use.


Finally I got some answer, ::test::GTEST_FLAG(list_tests) = true; //From your program, not w.r.t console.

If you would like to use --gtest_filter =*; /* =*, =xyz*... etc*/ // You need to use them in Console.

So, my requirement is to use them from the program not from the console.

Updated:-

Finally I got the answer for updating the same in from the program.

 ::testing::GTEST_FLAG(filter) = "*Counter*:*IsPrime*:*ListenersTest.DoesNotLeak*";//":-:*Counter*";
      InitGoogleTest(&argc, argv);
RUN_ALL_TEST();

So, Thanks for all the answers.

You people are great.