Ntest--An ultimate unit test framework for C++

Hi, everybody, I'm here to recommend a very nice, open source C++ unit test framework-Ntest, which I have developed myself. Ntest is deisgned in a simple, easy use and self-adapting way, by using Ntest, you can easily arrange your test projects. The most significant feature of Ntest is that, by using TestCase as a category to manage a single case, and inside TestCase, you can easily define different test units for different purpose. TestCase is act the same as a general c++ class or struct did, so you can define whatever you like inside TestCase' body, and no need to worry about name conflicting. By using TestCase, you can organize your test projects in a better and more pleasant way. A single piece of code example is enough to state its cleanness.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#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);
}


Here is the application's output

MaxMinTestCase
        TestMax ...Done!
        TestMin ...Done!
Done!
VectorTestCase
        TestAddItem ...Done!
        TestRemoveItem ...Done!
        TestInsertItem ...Done!
Done!
Congratulations, all tests have past!
Press any key to continue


Because the project has just began, I only make this program framework as simple as possible, but there are far more features that need to be strengthened and enriched. So what I needed now is supports and critical feedbacks from end users. If you found this interesting, try grabbing useful information from following links:

× Ntest's project page
http://code.google.com/p/ntestcpp/
× Help manual wiki page
http://code.google.com/p/ntestcpp/wiki/Help
× Source download
http://code.google.com/p/ntestcpp/downloads/list

If you have any questions, suggestions or needs, try discuss or commit your ideals by following way:

× Leave your message in this thread.
× Leave your message in the help manual page(recommended, so other people can view and discuss you opinion)
× send me an e-mail.

you can contact me by following way:
× My e-mail address
syjdeyouxiang@163.com
× My msn
kingsyj@live.cn

And finally, thanks for reading, having nice tests.
Topic archived. No new replies allowed.