How to run specific test cases in GoogleTest
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:
- Get all testcases by running tests with
--gtest_list_tests
- Parse this data into your GUI
- Select test cases you want ro run
- Run test executable with option
--gtest_filter
googletest: is it possible to select a single test fixture/case?
you can use the gtests command line option --gtest_filter
wehen invoking the executable for the debugging session. @see Running a Subset of the Tests
How to run part of the test cases using gtest
First, you don't need to write a main()
for gtest. You can just link with gtest_main
library as well as gtest
library. It is pretty similar to what you have, though.
Second, to run a specific test, please refer to advanced options.
How can you select specific Google Mock test cases/unit tests to run?
First of all, your unit tests should be lightning fast. Otherwise people are not going to execute them.
As explained in Selecting tests, you cam use --gtest_filter=
option. In your specific case : --gtest_filter=ClassAUnitTest.*
Is there a way to stop GoogleTest after a specific test is run, whether it passes or fails?
You have several options:
Simply call exit function at the end of
fooTest
.Create a test fixture. In
SetUp
check for a flag that is always false, but it sets to true iffooTest
is executed. Something like this:
bool skip_testing = false;
// Class for test fixture
class MyTestFixture : public ::testing::Test {
protected:
void SetUp() override {
if (skip_testing) {
GTEST_SKIP();
}
}
};
TEST_F(MyTestFixture, test1) {
//
EXPECT_EQ(1, 1);
}
TEST_F(MyTestFixture, footest) {
EXPECT_EQ(1, 1);
skip_testing = true;
}
TEST_F(MyTestFixture, test2) {
//
EXPECT_EQ(1, 1);
}
TEST_F(MyTestFixture, test3) {
//
EXPECT_EQ(1, 1);
}
See a working a working example here: https://godbolt.org/z/8dzKGE6Eh
- Similar to Option 2, but use explicit success and failure in
SetUp
instead ofGTEST_SKIP
. However usingGTEST_SKIP
is preferred, cause your output will show that the tests were skipped.
How do we run a single test using Google bazel
On Googletest with the following setup:
TEST(TestSuite, test1)
TEST(TestSuite, test2)
you can isolate test1 using
bazel test --test_arg=--gtest_filter=TestSuite.test $TEST_TARGET_PATH
See --gtest_filter
Related Topics
Base Pointer to Array of Derived Objects
Qt3D. Draw Transparent Qspheremesh Over Triangles
Are Class Members Guaranteed to Be Contiguous in Memory
Is a Logical Right Shift by a Power of 2 Faster in Avr
Infinite Loops - Top or Bottom
How to Compare Two Time Stamp in Format "Month Date Hh:Mm:Ss" to Check +Ve or -Ve Value
Why I Can Access Member Functions Even After the Object Was Deleted
C++ Visual Studio "Non-Standard Syntax; Use '&' to Create a Pointer to Member"
Opencv How to Select a Region of Image Irregularly with Mouse Event? C/C++
What Is C++ Version of Realloc(), to Allocate the New Buffer and Copy the Contents from the Old One
Can Raw Pointers Be Used Instead of Iterators with Stl Algorithms for Containers with Linear Storage
What Does "#Define Str(A) #A" Do
Convert String with Explicit Escape Sequence into Relative Character
Serializing Opencv Mat_<Vec3F>
Pass by Reference and Value with Pointers
How to Embed Webkit into My C/C++/Win32 Application
How to Optimize Matrix Multiplication (Matmul) Code to Run Fast on a Single Processor Core