赞
踩
CppTest是一个可移植、功能强大但简单的单元测试框架,用于处理C++中的自动化测试。重点在于可用性和可扩展性。支持多种输出格式,并且可以轻松添加新的输出格式。
CppTest下载地址Sourceforge Github地址
下面对其设计进行分析,以更好对其使用。
其类图如下:
说明:
RingQueueSuite: 2/2, 50% correct in 0.002901 seconds
Total: 2 tests, 50% correct in 0.002901 seconds
RingQueueSuite: 2/2, 50% correct in 0.002377 seconds
Test: one_to_multi
Suite: RingQueueSuite
File: cpp/test/concurrent/concurrent/ring_queue_test.cpp
Line: 90
Message: Got 5, expected 6
Total: 2 tests, 50% correct in 0.002377 seconds
如果是实时输出直接从Output派生,如果是收集型输出,需要从CollectorOutput派生。
cpptest默认输出都是英文信息,假如我们想输出中文信息及报告。我们需要:
#define TEST_ASSERT_EQUALS_MSG(expected, got, msg) \
{ \
if (!((got) == (expected))) \
{ \
std::stringstream tmpstream; \
tmpstream << (msg) << ": "; \
tmpstream << "Got " << (got) << ", expected " << (expected);\
assertment(::Test::Source(__FILE__, __LINE__, \
tmpstream.str().c_str())); \
if (!continue_after_failure()) return; \
} \
}
#define TEST_ASSERT_EQUALS_MSG(expected, got, msg) \
{ \
if (!((got) == (expected))) \
{ \
std::stringstream tmpstream; \
tmpstream << (msg) << ": "; \
tmpstream << "期望 " << (expected) << ", 实际是 " << (got); \
assertment(::Test::Source(__FILE__, __LINE__, \
tmpstream.str().c_str())); \
if (!continue_after_failure()) return; \
} \
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。