mirror of
https://github.com/php-win-ext/grpc.git
synced 2026-03-24 09:02:15 +01:00
Continuation of #37541 but focused on C++. Closes #37755 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37755 from NathanBaulch:typos-cpp 9a7fd9d65fa97a689d529772534df1a501031e9f PiperOrigin-RevId: 684600898
2.2 KiB
2.2 KiB
C++ tests on iOS
GTMGoogleTestRunner is used to convert googletest cases to XCTest that can be run on iOS. GTMGoogleTestRunner doesn't execute the main function, so we can't have any test logic in main.
However, it's ok to call ::testing::InitGoogleTest in main, as GTMGoogleTestRunner calls InitGoogleTest.
grpc::testing::TestEnvironment can also be called from main, as it does some test initialization (install crash handler, seed RNG) that's not strictly required to run testcases on iOS.
Porting existing C++ tests to run on iOS
Please follow these guidelines when porting tests to run on iOS:
- Tests need to use the googletest framework
- Any setup/teardown code in
mainneeds to be moved toSetUpTestCase/TearDownTestCase, andTESTneeds to be changed toTEST_F. - Death tests are not supported on iOS, so use the
*_IF_SUPPORTED()macros to ensure that your code compiles on iOS.
For example, the following test
TEST(MyTest, TestOne) {
ASSERT_DEATH(ThisShouldDie(), "");
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
grpc_init();
return RUN_ALL_TESTS();
grpc_shutdown();
}
should be changed to
class MyTest : public ::testing::Test {
protected:
static void SetUpTestCase() { grpc_init(); }
static void TearDownTestCase() { grpc_shutdown(); }
};
TEST_F(MyTest, TestOne) {
ASSERT_DEATH_IF_SUPPORTED(ThisShouldDie(), "");
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Limitations
Due to a limitation in GTMGoogleTestRunner, SetUpTestCase/TeardownTestCase will be called before/after every individual test case, similar to SetUp/TearDown.