You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a general approach to translate tests between GTest and CppTest:
Test Cases: Replace GTest's TEST macro with CppTest's TEST macro within a TEST_SUITE.
Test Fixtures:
GTest: Inherit from ::testing::Test and use SetUp()/TearDown().
CppTest: Create a class with setup()/teardown() methods and use TEST_FIXTURE.
Assertions: Map GTest's ASSERT_* and EXPECT_* macros to their CppTest CHECK equivalents. Here's a basic mapping:
GTest
CppTest
ASSERT_EQ
CHECK_EQUAL
EXPECT_EQ
CHECK_EQUAL (non-fatal variations exist)
ASSERT_TRUE
CHECK
EXPECT_TRUE
CHECK (non-fatal variations exist)
ASSERT_NE
CHECK_NOT_EQUAL
EXPECT_NE
CHECK_NOT_EQUAL (non-fatal variations exist)
ASSERT_THROW
CHECK_THROW
EXPECT_THROW
CHECK_THROW (non-fatal variations exist)
Example Translation (GTest to CppTest):
GTest:
TEST(MySuite, MyTest) {
int x = 5;
ASSERT_EQ(x, 5);
EXPECT_TRUE(x > 0);
}
CppTest:
TEST_SUITE(MySuite) {
TEST(MySuite, MyTest) {
int x = 5;
CHECK_EQUAL(x, 5);
CHECK(x > 0);
}
}
Challenges and Considerations
Mocking: GTest has Google Mock, while CppTest has its own mocking framework. Translating mocks might require more effort.
Advanced Features: GTest and CppTest have unique advanced features (e.g., parameterized tests, death tests, etc.) that might not have direct equivalents.
Test Runner: The test runners for GTest and CppTest are different, so you'll need to adjust your build system and execution commands.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Comparing Google Test (GTest) and CppTest in terms of their class and assertion structures, and how to translate tests between them.
Class Structures
TEST
,TEST_F
,TEST_P
) to define test cases. Test fixtures are created by defining classes that inherit from::testing::Test
.TEST_SUITE
,TEST
) to define test suites and cases. Test fixtures are classes with specialsetup()
andteardown()
methods.Assertion Structures
ASSERT_*
(fatal) andEXPECT_*
(non-fatal) macros for assertions.CHECK
macros for assertions (mostly fatal, with some non-fatal variations).Translating Between GTest and CppTest
Here's a general approach to translate tests between GTest and CppTest:
Test Cases: Replace GTest's
TEST
macro with CppTest'sTEST
macro within aTEST_SUITE
.Test Fixtures:
::testing::Test
and useSetUp()
/TearDown()
.setup()
/teardown()
methods and useTEST_FIXTURE
.Assertions: Map GTest's
ASSERT_*
andEXPECT_*
macros to their CppTestCHECK
equivalents. Here's a basic mapping:ASSERT_EQ
CHECK_EQUAL
EXPECT_EQ
CHECK_EQUAL
(non-fatal variations exist)ASSERT_TRUE
CHECK
EXPECT_TRUE
CHECK
(non-fatal variations exist)ASSERT_NE
CHECK_NOT_EQUAL
EXPECT_NE
CHECK_NOT_EQUAL
(non-fatal variations exist)ASSERT_THROW
CHECK_THROW
EXPECT_THROW
CHECK_THROW
(non-fatal variations exist)Example Translation (GTest to CppTest):
GTest:
CppTest:
Challenges and Considerations
Beta Was this translation helpful? Give feedback.
All reactions