mirror of
https://github.com/php-win-ext/grpc.git
synced 2026-03-24 17:12:19 +01:00
* Refactor end2end tests to exercise each EventEngine * fix incorrect bazel_only exclusions * Automated change: Fix sanity tests * microbenchmark fix * sanitize, fix iOS flub * Automated change: Fix sanity tests * iOS fix * reviewer feedback * first pass at excluding EventEngine test expansion Also caught a few cases where we should not test pollers, but should test all engines. And two cases where we likely shouldn't be testing either product. * end2end fuzzers to be fuzzed differently via EventEngine. * sanitize * reviewer feedback * remove misleading comment * reviewer feedback: comments * EE test_init needs to play with our build system * fix golden file test runner Co-authored-by: drfloob <drfloob@users.noreply.github.com>
53 lines
2.2 KiB
Markdown
53 lines
2.2 KiB
Markdown
## C++ tests on iOS
|
|
|
|
[GTMGoogleTestRunner](https://github.com/google/google-toolbox-for-mac/blob/master/UnitTesting/GTMGoogleTestRunner.mm) 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](https://github.com/google/google-toolbox-for-mac/blob/master/UnitTesting/GTMGoogleTestRunner.mm#L151).
|
|
`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](https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#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
|
|
```c++
|
|
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
|
|
```c++
|
|
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](https://github.com/google/google-toolbox-for-mac/blob/master/UnitTesting/GTMGoogleTestRunner.mm#L48-L56) in GTMGoogleTestRunner, `SetUpTestCase`/`TeardownTestCase` will be called before/after *every* individual test case, similar to `SetUp`/`TearDown`.
|