WebKit的智能指针分析 - Part 1:RefCounted

CppUnit 笔记

obi posted @ 2010年11月07日 19:39 in C++ with tags 单元测试 , 2868 阅读

 

最近在重写一个私人项目,为了提高项目质量,决定使用CppUnit做单元测试。 CppUnit已久仰大名,但由于之前主要做C的项目,使用的都是自己写的 ASSERT库,因此刚一上手时对CppUnit的一些概念的理解比较乱,不过在第N遍阅 读Cookbook后还算是理清了一些概念。

1 TestCase, Fixture and Suit

Cppunit通过上面三个概念(类)来组织测试用例。一般来说,一个Fixture包含 了N个TestCase,而一个Suit又包含了N个Fixture。用图表示就是下面这样: 

2 Helper Macros

在Helper Macros出现之前,把N个case加到一个suit里是一件非常机械的事, 它不仅要求为一个Fixture子类提供一个静态的suit()函数成员,它还意味着重 复写个类似于

suite.addTest( 
             new CppUnit::TestCaller<ComplexNumberTest>( "testEquality",
                                                         &ComplexNumberTest::testEquality )
             );

的代码,而这种代码一旦多了就容易造成笔误。因此 CppUnit提供了一些宏如 CPPUNIT_TEST_SUITECPPUNIT_TEST_EXCEPTION 等来帮助开发人员减少这 种情况的发生。 使用 CPPUNIT_TEST_SUITE 后,写成:

CPPUNIT_TEST( testEquality )

就行了。

3 TestFactoryRegistry

TestFactoryRegistry的存在是为了解决两个问题:

  • 忘记将某个fixture添加进suit
  • 有多少个suit就有多少个#include (一般一个suit放到一个文件里)
full part time maids 说:
2021年10月02日 17:04

A building cleaning business won't sound so that you can exciting but it might be very fine money brewer, let's facial area it what amount of people do like now there job not much of a lot, but whether it's your private business this is the completely different pastime, if you improve it and you simply are used to what you actually doing you may grow them big more than enough to finally hire quite a few employees to undertake the be good enough. I reckon the sky is a limit.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter