summaryrefslogtreecommitdiffstats
path: root/googletest/test/gtest_unittest.cc
diff options
context:
space:
mode:
authormisterg <misterg@google.com>2019-01-03 17:39:44 (GMT)
committerGennadiy Civil <misterg@google.com>2019-01-03 21:40:20 (GMT)
commit3a460a26b7a91abf87af7f31b93d29f930e25c82 (patch)
tree286a8c244c42d40f2117ccabe41eb3aff8132cdf /googletest/test/gtest_unittest.cc
parentac8c102dae661b8bff6780ffdc535c6d1957d45b (diff)
downloadgoogletest-3a460a26b7a91abf87af7f31b93d29f930e25c82.zip
googletest-3a460a26b7a91abf87af7f31b93d29f930e25c82.tar.gz
googletest-3a460a26b7a91abf87af7f31b93d29f930e25c82.tar.bz2
Googletest export
TestCase->TestSuite refactoring PiperOrigin-RevId: 227702164
Diffstat (limited to 'googletest/test/gtest_unittest.cc')
-rw-r--r--googletest/test/gtest_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 307f630..6c7d551 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -5431,6 +5431,67 @@ TEST_F(SetUpTestCaseTest, Test2) {
EXPECT_STREQ("123", shared_resource_);
}
+// Tests SetupTestSuite/TearDown TestSuite API
+class SetUpTestSuiteTest : public Test {
+ protected:
+ // This will be called once before the first test in this test case
+ // is run.
+ static void SetUpTestSuite() {
+ printf("Setting up the test suite . . .\n");
+
+ // Initializes some shared resource. In this simple example, we
+ // just create a C string. More complex stuff can be done if
+ // desired.
+ shared_resource_ = "123";
+
+ // Increments the number of test cases that have been set up.
+ counter_++;
+
+ // SetUpTestSuite() should be called only once.
+ EXPECT_EQ(1, counter_);
+ }
+
+ // This will be called once after the last test in this test case is
+ // run.
+ static void TearDownTestSuite() {
+ printf("Tearing down the test suite . . .\n");
+
+ // Decrements the number of test suites that have been set up.
+ counter_--;
+
+ // TearDownTestSuite() should be called only once.
+ EXPECT_EQ(0, counter_);
+
+ // Cleans up the shared resource.
+ shared_resource_ = nullptr;
+ }
+
+ // This will be called before each test in this test case.
+ void SetUp() override {
+ // SetUpTestSuite() should be called only once, so counter_ should
+ // always be 1.
+ EXPECT_EQ(1, counter_);
+ }
+
+ // Number of test suites that have been set up.
+ static int counter_;
+
+ // Some resource to be shared by all tests in this test case.
+ static const char* shared_resource_;
+};
+
+int SetUpTestSuiteTest::counter_ = 0;
+const char* SetUpTestSuiteTest::shared_resource_ = nullptr;
+
+// A test that uses the shared resource.
+TEST_F(SetUpTestSuiteTest, TestSetupTestSuite1) {
+ EXPECT_STRNE(nullptr, shared_resource_);
+}
+
+// Another test that uses the shared resource.
+TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
+ EXPECT_STREQ("123", shared_resource_);
+}
// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.