22 | | There is no documentation as of now. Feel free to ask for help by e-mailing sam@hocevar.net. |
23 | | |
24 | | A good way to understand how to use LolUnit is by comparing it with CppUnit’s helper macros. Here is a sample program using CppUnit: |
25 | | |
26 | | {{{ |
27 | | #!cpp |
28 | | #include <cppunit/extensions/HelperMacros.h> |
29 | | #include <cppunit/extensions/TestFactoryRegistry.h> |
30 | | #include <cppunit/TestCaller.h> |
31 | | #include <cppunit/TestCase.h> |
32 | | #include <cppunit/TestSuite.h> |
33 | | #include <cppunit/TextTestRunner.h> |
34 | | |
35 | | class Test1 : public CppUnit::TestCase |
36 | | { |
37 | | CPPUNIT_TEST_SUITE(Test1); |
38 | | CPPUNIT_TEST(Addition); |
39 | | CPPUNIT_TEST(Multiplication); |
40 | | CPPUNIT_TEST_SUITE_END(); |
41 | | |
42 | | void Addition() |
43 | | { |
44 | | int i = 1; |
45 | | CPPUNIT_ASSERT_EQUAL(i + 1, 2); |
46 | | CPPUNIT_ASSERT_EQUAL(i + 2, 3); |
47 | | } |
48 | | |
49 | | void Multiplication() |
50 | | { |
51 | | int i = 2; |
52 | | CPPUNIT_ASSERT_EQUAL(i * 1, 2); |
53 | | CPPUNIT_ASSERT_EQUAL(i * 2, 4); |
54 | | } |
55 | | }; |
56 | | CPPUNIT_TEST_SUITE_REGISTRATION(Test1); |
57 | | |
58 | | int main(void) |
59 | | { |
60 | | CppUnit::TextTestRunner runner; |
61 | | runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); |
62 | | return !runner.run(); |
63 | | } |
64 | | }}} |
65 | | |
66 | | One major problem I have with this system is that `Addition` needs to be declared and defined at two different places. Similarly, `Test1` needs to be declared, then given as an argument to `CPPUNIT_TEST_SUITE`, and finally as an argument to `CPPUNIT_TEST_SUITE_REGISTRATION`. There is no reason the user should have to duplicate this information. |
67 | | |
68 | | This is the LolUnit equivalent: |
69 | | |
70 | | {{{ |
71 | | #!cpp |
72 | | #include <lol/unit.h> |
73 | | |
74 | | LOLUNIT_FIXTURE(Test1) |
75 | | { |
76 | | LOLUNIT_TEST(Addition) |
77 | | { |
78 | | int i = 1; |
79 | | LOLUNIT_ASSERT_EQUAL(i + 1, 2); |
80 | | LOLUNIT_ASSERT_EQUAL(i + 2, 3); |
81 | | } |
82 | | |
83 | | LOLUNIT_TEST(Multiplication) |
84 | | { |
85 | | int i = 2; |
86 | | LOLUNIT_ASSERT_EQUAL(i * 1, 2); |
87 | | LOLUNIT_ASSERT_EQUAL(i * 2, 4); |
88 | | } |
89 | | }; |
90 | | |
91 | | int main(void) |
92 | | { |
93 | | lol::TextTestRunner runner; |
94 | | return !runner.run(); |
95 | | } |
96 | | }}} |
97 | | |
98 | | We believe it is a lot simpler. |
| 27 | See the [wiki:/oss/lolunit/tutorial LolUnit tutorial] for an introduction on how to use LolUnit. |