I am trying to write a function/method for my project, which will ask to user which all test cases are you going to run? It looks like below...,
Test_Cases_1
|_TestNo1
|_TestNo2....so on
Test_Cases_2
|_TestNo1
|_TestNo2....so on
....
....so on
Test_Cases_N
|_TestNo1
|_TestNo2....so on
So, now the challenge is while running the project it should prompt me what all test cases you would like to execute?
If I select Test_Cases_1
and Test_Cases_N
. Then it should execute these two test cases and should exclude all other from Test_Cases_2 to ....
. In result window also I would like to see the results of Test_Cases_1
and Test_Cases_N
.
So, if I will see the GoogleTest, there is a method called test_case_to_run_count()
;
But all the test cases
are getting registered with Test_F() method.
So, I did lots of analysis, but still did not find any solution.
Please help me.
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.
So, Thanks for all the answers.
You people are great.
Summarising @Rasmi Ranjan Nayak and @nogard answers and adding another option:
On the console
You should use the flag
--gtest_filter
, like(You can also do this in Properties|Configuration Properties|Debugging|Command Arguments)
On the environment
You should set the variable
GTEST_FILTER
likeOn the code
You should set a flag
filter
, likesuch that your main function becomes something like
See section Running a Subset of the Tests for more info on the syntax of the string you can use.
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 which is regular expression. 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:
--gtest_list_tests
--gtest_filter