Jan Tattermusch 3a37f901e8 Merge pull request #20956 from jtattermusch/win_timer_tests 6 سال پیش
..
client b2b7fc9af8 Replaced grpc_core::UniquePtr with std::unique_ptr 6 سال پیش
cocoapods 7ec6e8a4de Remove nanopb from gRPC 6 سال پیش
codegen c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
common 44f6b99d07 disable flaky timer_test on windows 6 سال پیش
end2end b2b7fc9af8 Replaced grpc_core::UniquePtr with std::unique_ptr 6 سال پیش
ext c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
grpclb c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
interop c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
ios eae902594b Merge pull request #19855 from Tony1023/bazel_objc_tests 6 سال پیش
microbenchmarks 3a519a0b64 Replaced grpc_core New & Delete with C++ new & delete 6 سال پیش
naming b2b7fc9af8 Replaced grpc_core::UniquePtr with std::unique_ptr 6 سال پیش
performance c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
qps b2b7fc9af8 Replaced grpc_core::UniquePtr with std::unique_ptr 6 سال پیش
server c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
test c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
thread_manager c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
util c34bef4ca4 Format all Bazel files with buildifier 6 سال پیش
README-iOS.md b436758b14 Added documentation for C++ tests on iOS 6 سال پیش

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.