测试自动化 2011/06/11 - 3 GTest Samples

本文深入探讨了谷歌测试框架的关键特性,包括测试固定装置的作用、独立测试的重要性、SetUp()与TearDown()方法的用途,以及如何正确使用宏来指示测试的成功或失败。此外,还分析了构建过程中出现的错误,并提供了可能的解决方案。

0. 杂问杂记

 

1. Sample 3

* Fixture

// The tests share the test fixture in the sense of code sharing, not
// data sharing.  Each test is given its own fresh copy of the
// fixture.  You cannot expect the data modified by one test to be
// passed on to another test, which is a bad idea.

 

test-independency!

 

* SetUp() / TearDown()

All "virtual"

 

Q: Why ?

 

 

* Questions

// The macros for indicating the success/failure of a test
// (EXPECT_TRUE, FAIL, etc) need to know what the current test is
// (when Google Test prints the test result, it tells you which test
// each failure belongs to).  Technically, these macros invoke a
// member function of the Test class.  Therefore, you cannot use them
// in a global function.  That's why you should put test sub-routines
// in a test fixture.

 

What does this mean ?

 

2. Sample 4

3. Sample 5

fixtues for multiple test cases: super Fixture !

 

make错误如下:

 

[root@localhost make]# make -f Makefile-4 clean
rm -f sample4_unittest *.o
[root@localhost make]# make -f Makefile-4
g++ -I../include -g -Wall -Wextra -c ../samples/sample4_unittest.cc ../samples/sample1.h ../samples/sample3-inl.h
g++ -I../include -I.. -g -Wall -Wextra -c /
            ../src/gtest-all.cc
在包含自 ../src/gtest-all.cc:42 的文件中:
../src/gtest.cc:34:25: 错误:calling fdopen:错误的文件描述符
在包含自 ../src/gtest.cc:132 的文件中,
                 从 ../src/gtest-all.cc:42:
../src/gtest-internal-inl.h:65:36: 错误:calling fdopen:错误的文件描述符
在包含自 ../src/gtest-all.cc:48 的文件中:
../src/gtest-typed-test.cc:33:25: 错误:calling fdopen:错误的文件描述符
make: *** [gtest-all.o] 错误 1

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值