Test the API works, do not test private member. (Test the use of consumer. )
Test shows how the usage of API
Resilience
Don’t write flaky test. (re-run get different result.)
Don’t write brittle test. (tests those may fail with unrelated code change.)[hermeticity, order, Deep Dependence]
sleep(1);// may failure if test timeout is 0.5---------------------fopen();//may fail if multi test read/write a same file. (should be hermeticity)---------------------staticint i =0;// may fail TEST(Foo, First){.....++i;}TEST(Foo, Second){.....++i;}----------------------
文章目录CorrectnessReadabilityCompletenessDemonstrabilityResilienceCorrectnessDoesn’t write depend on known bugs// DO NOT DO THIS!!!int square(int x){ // TODO return 0;}TEST(SqureTest, MathTest){ EXPECT_EQ(0, square(2));}Write Test base on rea.