Mark D. Roth df062598c0 Merge pull request #25379 from bojeil-google/master před 4 roky
..
client 33b80f16ec Applies clang_format_code.sh to address sanity check tests. před 4 roky
cocoapods 86050be0cf Clean up DEPLOYMENT_TARGET před 5 roky
codegen 27e1c1c56d clang-tidy: enable google-readability-braces-around-statements před 4 roky
common 6a1518bd22 Made grpc_core::Mutex compatible to absl::Mutex před 4 roky
end2end 6f339894f1 Merge pull request #25325 from veblush/mutex-api před 4 roky
ext 9bd7c4917a Fix unused-parameter warning před 4 roky
grpclb 62ac3f075a Added call to grpc::testing::TestEnvironment in tests před 5 roky
interop b2443df1e1 xds_interop_client.cc modification: new stats and new timeout_sec config před 4 roky
ios 0e7faed883 Fix flaky ios-cpp-test-cronet test. před 4 roky
microbenchmarks 9bd7c4917a Fix unused-parameter warning před 4 roky
naming c6c3dc57af Remove unneeded filter před 4 roky
performance e7434d385e Fix by tidy-modernize-use-override před 5 roky
qps be761cd430 Fixed sign-compare warnings před 4 roky
server f171a6689e Fix StatusCode před 4 roky
test 165ee5007a Replaced grpc::string with std::string před 5 roky
thread_manager 131579d52d Roll forward of commit 7883b51: Use abseil's flags in tests. před 4 roky
util 9eabb96f1c Added no_test_ios to error_details_test před 4 roky
README-iOS.md b436758b14 Added documentation for C++ tests on iOS před 6 roky

README-iOS.md

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 exising 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 main needs to be moved to SetUpTestCase/TearDownTestCase, and TEST needs to be changed to TEST_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.