Ntest -- C++平台的终极测试
大家好,我向各位推荐我个人编写的一个开源的单元测试平台Ntest。Ntest是一个设计简单、易于使用并具有自适应能力的单元测试框架,通过Ntest你可以轻松构建您的测试项目。其特点之一为,通过TestCase来管理单个用例,再在用例内部构建各个测试单元,TestCase的操作与CPP类的操作一致,你可以在用例内部定义变量,辅助函数,而不用担心在名称上存在冲突,通过TestCase你将能够更好地管理、组织您的测试单元,以下通过一个简单例子便可阐述其编码的简洁性:
// NtestSample.cpp
#include <ntest.h> // include test framework header
#include <vector>
// building test targets
template<typename T>
T Max(const T & InA, const T & InB)
{
return InA < InB ? InB : InA;
}
template<typename T>
T Min(const T & InA, const T & InB)
{
return InA < InB ? InA : InB;
}
// declare test case
NCASE(MaxMinTestCase)
{
// declare test unit
NTEST(TestMax)
{
// verify the return value is 4
NEQ(Max(3, 4), 4);
NEQ(Max(4, 3), 4);
NEQ(Max(4, 4), 4);
}
NTEST(TestMin)
{
NEQ(Min(3, 4), 3);
NEQ(Min(4, 3), 3);
NEQ(Min(3, 3), 3);
}
};
// register test case
NADD(MaxMinTestCase)
// another test case
NCASE(VectorTestCase)
{
// initialize the sample
void setup()
{
Vector.push_back(0);
Vector.push_back(1);
Vector.push_back(2);
Vector.push_back(3);
Vector.push_back(4);
}
// begin our tests
NTEST(TestAddItem)
{
NEQ(Vector.size(), 5);
int ArraySample[] = { 0, 1, 2, 3, 4 };
// verify two array is equal
NARRAYEQ(&Vector[0], ArraySample, 5);
}
NTEST(TestRemoveItem)
{
Vector.erase(Vector.begin() + 2);
int ArraySample[] = { 0, 1, 3, 4 };
NEQ(Vector.size(), 4);
NARRAYEQ(&Vector[0], ArraySample, 4);
}
NTEST(TestInsertItem)
{
Vector.insert(Vector.begin() + 2, 9);
int ArraySample[] = { 0, 1, 9, 3, 4 };
NEQ(Vector.size(), 5);
NARRAYEQ(&Vector[0], ArraySample, 5);
}
// declare a usage sample
std::vector<int> Vector;
};
NADD(VectorTestCase)
void main()
{
// run test
NRUN(NULL);
}
编译运行程序,其输出结果为:
MaxMinTestCase
TestMax ...Done!
TestMin ...Done!
Done!
VectorTestCase
TestAddItem ...Done!
TestRemoveItem ...Done!
TestInsertItem ...Done!
Done!
Congratulations, all tests have past!
Press any key to continue
由于项目才处于起步阶段,我只提供了一个非常简单的代码框架,其中有大量的内容需要丰富。因此我需要获取尽可能多的用户反馈,如果您对此感兴趣,请通过以下链接获取你需要的信息:
× Ntest项目主页
http://code.google.com/p/ntestcpp/
× 项目帮助文档WIKI
http://code.google.com/p/ntestcpp/wiki/Help
× 下载源码
http://code.google.com/p/ntestcpp/downloads/list
如果你有任何问题,建议或者需求,请通过以下方式提交:
×在本贴留言
×在项目帮助文档WIKI页面留言
×向我发送E-MAIL
我将及时处理您的请求。
您可以通过以下方式与我取得联系:
×电子邮箱
syjdeyouxiang@163.com
×MSN
kingsyj@live.cn
最后非常感谢各位浏览本贴,祝大家工作顺利,测试愉快!
[解决办法]
呵呵,不错,试试