测试自动化 2011/06/12 - 4 GTest Advanced Guide

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值