classXXXEnvironment:publictesting::Environment{public:virtualvoidSetUp(){...}virtualvoidTearDown(){...}};// add to gtestintmain(intargc,char**argv){test::AddGlobalTestEnvironment(newXXXEnvironment);...}
classXXXTest:publictesting::Test{// or publicprotected:// can be used to initializestaticvoidSetUpTestCase(){...}staticvoidTearDownTestCase(){...}};// use TEST_F to use XXXTestTEST_F(XXXTest,Test){...}
EXPECT_CALL(mock_object,Method(argument-matchers))// mock_object为模拟的对象,Method为mock_object中的mock方法。.With(multi-argument-matchers).Times(cardinality).InSequence(sequences)// InSquence用于指定函数执行的顺序,通过同意序列中声明期待的顺序确定.After(expectations).WillOnce(action).WillRepeatedly(action).RetiresOnSaturation();// where all clauses are optional, and .InSequence()/.After()/.WillOnce() can appear any number of times.