gtest Use Summary

gtest is Google publishing unit testing framework, and powerful. Examples of binding Google source code that came with the simple precautions are summarized below.

1, unit testing is how to start running

Each item is a unit test exe, and exe necessarily have as a main entry point. There are two main ways to introduce gtest of.

1, add a reference to gtest_main.dll dynamic library, the library is actually only one function, that is the main export function. In this way the need to actively function in the master unit declaration main test code.

2 embodiment, the main display main function is added, this time to pay attention to add InitGoogleTest (& argc, argv);

RUN_ALL_TESTS (); two unit functions called to start testing.

       2, general usage

       TEST(TESTGROUP, CASE1) {

            EXPECT_EQ(1, 1);

}

TEST(TESTGROUP, CASE2) {

            EXPECT_NE (1, 2) << "should equal";

}

TESTGROUP is the name of the test group, CASE1 is the name of each test item.

EXPECT_EQ

EXPECT_STREQ

It is a series of predicate function, pay attention to change the function can insert a variety of tips, estimated to be a ostream.

Each method of each class should have a corresponding test case

EXPECT_ * is false the program will continue to run, should this be the case test estimates established.

ASSERT_ * Series program directly terminates.

3, public fixed facilities

Inherited from testing :: Test, for example, MyTest: public testing :: Test, and then rewrite SetUp TearDown function.

Then test written

TEST_F(MyTest, test1) {

}

TEST_F(MyTest, test2) {

}

Each test will then instantiate the class once.

4 different types of tests

Commonly used template can be passed in different types. Also to be inherited from testing :: Test, and then use a different test macro definition TYPED_TEST.

5, test different parameters

Test different functions, inherited from TestWithParam <>, then use TEST_P

Note that when there are two or more parameters can be combined,

6, listener

At this point the need to write your own main function

Guess you like

Origin www.cnblogs.com/ljy339/p/11443613.html