Version 2 (modified by 12 years ago) (diff) | ,
---|
The LolUnit test framework
LolUnit came from a need to for a lightweight unit test system. Our previous framework of choice was CppUnit, but we stopped using it because there was no practical way to pre-build it for all the platforms we support (Windows with various compilers, Android, iOS, PS3…). Also, we had to keep as many precompiled binaries as there were versions of libstdc++, multiplied by the number of possible configurations (debug, release…). This was very difficult to maintain.
Though we use it in production code, LolUnit’s overall quality should not be considered higher than proof of concept for now.
LolUnit offers the following features, which can also be seen as limitations if your requirements are very different from ours:
- comes as a single
.h
header - does not require an external library
- does not require any information duplication
- can be built with
-fno-exceptions -fno-rtti
- formats its standard text output in the same way as CppUnit
Download
Download the single <lol/unit.h> file.
Documentation
There is no documentation as of now. Feel free to ask for help by e-mailing sam@hocevar.net.
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:
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/TestCaller.h> #include <cppunit/TestCase.h> #include <cppunit/TestSuite.h> #include <cppunit/TextTestRunner.h> class Test1 : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(Test1); CPPUNIT_TEST(Addition); CPPUNIT_TEST(Multiplication); CPPUNIT_TEST_SUITE_END(); void Addition() { int i = 1; CPPUNIT_ASSERT_EQUAL(i + 1, 2); CPPUNIT_ASSERT_EQUAL(i + 2, 3); } void Multiplication() { int i = 2; CPPUNIT_ASSERT_EQUAL(i * 1, 2); CPPUNIT_ASSERT_EQUAL(i * 2, 4); } }; CPPUNIT_TEST_SUITE_REGISTRATION(Test1); int main(void) { CppUnit::TextTestRunner runner; runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); return !runner.run(); }
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
.
This is the LolUnit equivalent:
#include <lol/unit.h> LOLUNIT_FIXTURE(Test1) { LOLUNIT_TEST(Addition) { int i = 1; LOLUNIT_ASSERT_EQUAL(i + 1, 2); LOLUNIT_ASSERT_EQUAL(i + 2, 3); } LOLUNIT_TEST(Multiplication) { int i = 2; LOLUNIT_ASSERT_EQUAL(i * 1, 2); LOLUNIT_ASSERT_EQUAL(i * 2, 4); } }; int main(void) { lol::TestTextRunner runner; return !runner.run(); }
Attachments (1)
-
lolunit-0.1.tar.gz (3.3 KB) - added by 12 years ago.
LolUnit 0.1
Download all attachments as: .zip