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);

本文详细介绍了GoogleTest框架中的各种断言用法,包括如何使错误消息更具可读性、预定义的断言宏、断言放置的最佳实践及如何定制输出信息等。适合希望深入了解GoogleTest并提高单元测试质量的开发者。
3367

被折叠的 条评论
为什么被折叠?



