Jan Tattermusch 047c2d476f Merge pull request #21739 from grpc/vjpai-patch-1 5 vuotta sitten
..
client ee7ae056e5 Revert "Updates to TLS credentials, version 3" 5 vuotta sitten
cocoapods 7ec6e8a4de Remove nanopb from gRPC 6 vuotta sitten
codegen 8d9d8326f5 De-experimentalize generated code 5 vuotta sitten
common 257411aa2d Fix test flakiness 5 vuotta sitten
end2end cf032b300e xds: Fix crash when moving all localities from a priority to a higher priority. 5 vuotta sitten
ext 2e958cf01b (Census client filter: use current span and tags. original_author=g-easy) 5 vuotta sitten
grpclb ef050280af Clean up APIs for handling grpclb protos 5 vuotta sitten
interop a77d7c0f5a Merge pull request #21999 from yashykt/xdsinteropclangtidy 5 vuotta sitten
ios 63223f82e8 fix sanity 5 vuotta sitten
microbenchmarks f7d857a8e4 Make threadpool and trickle tests manual only (excessive time/resources) 5 vuotta sitten
naming 283574e3b7 Convert service config code to use new JSON API 5 vuotta sitten
performance 5bc57b64fe InitGoogleTest before grpc_init 5 vuotta sitten
qps 6622c94c17 Shutdown server properly before CQs 5 vuotta sitten
server 9ae81e1d3f Make test code use TestEnvironment 5 vuotta sitten
test c34bef4ca4 Format all Bazel files with buildifier 5 vuotta sitten
thread_manager c34bef4ca4 Format all Bazel files with buildifier 5 vuotta sitten
util bc5e3fb661 Convert channelz code to use new JSON API 5 vuotta sitten
README-iOS.md b436758b14 Added documentation for C++ tests on iOS 6 vuotta sitten

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.