PSCF v1.1
example1.cpp
1#include <UnitTest.h>
2#include <UnitTestRunner.h>
3#include <iostream>
4
20class TestA : public UnitTest
21{
22
23public:
24
25 void test1() {
26 printMethod(TEST_FUNC);
27 TEST_ASSERT(eq(1,2));
28 }
29
30 void test2() {
31 printMethod(TEST_FUNC);
32 TEST_ASSERT(false);
33 }
34
35 void test3() {
36 printMethod(TEST_FUNC);
37 TEST_ASSERT(3 == 3);
38 }
39
40};
41
42/*
43* Preprocessor macros to define an associated UnitTestRunner.
44*
45* The name of the runner class in this example TestA_Runner.
46* The name of the runner class created by the TEST_BEGIN() macro
47* by pasting the suffix _Runner onto the end of class name.
48*/
49TEST_BEGIN(TestA)
50TEST_ADD(TestA, test1)
51TEST_ADD(TestA, test2)
52TEST_ADD(TestA, test3)
53TEST_END(TestA)
54
55/*
56* The above macros expand into the following class definition:
57*
58* class TestA_Runner : public UnitTestRunner<TestA> {
59* public:
60*
61* TestA_Runner() {
62* addTestMethod(&TestA::test1);
63* addTestMethod(&TestA::test2);
64* addTestMethod(&TestA::test3);
65* }
66*
67* };
68*/
69
70/*
71* Main program to run tests.
72*
73* The preprocessor macro TEST_RUNNER(TestA) expands to TestA_Runner.
74*/
75int main()
76{
77 TEST_RUNNER(TestA) test;
78 test.run();
79}
This example shows how to construct and run a single UnitTest class.
Definition: example1.cpp:21
UnitTest is a base class for classes that define unit tests.
Definition: UnitTest.h:51
static bool eq(int s1, int s2)
Return true if two integers are equal.
Definition: UnitTest.h:403
void printMethod(const char *methodName)
Write name of a class method, iff ioProcessor.
Definition: UnitTest.h:314