0. 杂问杂记
Unlike TestNG, GoogleTest does not use Exception to report failure/success of a test.
1. More assertions
Focus: to make the error message more readable.
* Exception Assertions
ASSERT_THROW( statement , exception_type );
^ What's this ?
* Predicate assertion
ASSERT_PRED1(pred1, val1);
ASSERT_PRED2(pred2, val1, val2);
* ActionResult
例:
::testing::AssertionResult IsEven(int n)
Q:似乎把测试的写进了生产代码???
* Floating-point comparison(略)
* Type Assertions
2. Assertions placement
You can use assertions in any C++ function. In particular, it doesn't
have to be a method of the test fixture class. The one constraint is
that assertions that generate a fatal failure (FAIL* and ASSERT_*) can only be used in void-returning functions.
Note
: Constructors and destructors are not considered
void-returning functions, according to the C++ language specification,
and so you may not use fatal assertions in them.
3. 输出信息定制
operator << (::std::ostream &os, const T &t);
void PrintTo(const T &t, ::std::ostream *os);