UquoniTest
Writing a test in UquoniTest is quite simple. In a source file you just include the UquoniTest header file, the header files of the code you want to test, and uqtTEST followed by a unique name between parentheses, and the test code between bracelets. There is no need to register the test, the macro uqtTEST takes care of that.
#include "uquonitest/Test.hpp" #include "MyClass.hpp" uqtTEST(MyClass) { MyClass obj; obj.SetFirstName("Jack"); obj.SetSurName("Jones"); uqtASSERT(rbEQUAL("Jack Jones", obj.GetFullName())); }Tests can be put in groups. If you do this you can select tests to be run by group, you can have setup and teardown per group, and you can have test wrappers that are only active in a group. Furthermore test results are also shown per group, e.g. if you expect errors in one group, but you see that there are errors in two groups, you know directly there is more at hand.
#include "uquonitest/Test.hpp" #include "MyClass.hpp" uqtTEST_GROUP(MyClass) { uqtTEST(GetFullName) { MyClass obj; obj.SetFirstName("Jack"); obj.SetSurName("Jones"); uqtASSERT(rbEQUAL("Jack Jones", obj.GetFullName())); } }
Having a test group makes it easy to use fixtures. A fixture is an object of which you can use the members directly in the test. Setup and teardown can be done in the constructor and destructor of the object. This is useful if several tests use the same data, setup and teardown. In UquoniTest you do this by creating a class called uqtFixture, and using uqtTESTF instead of uqtTEST.
#include "uquonitest/Test.hpp" #include "MyClass.hpp" uqtTEST_GROUP(MyClass) { class uqtFixture { public: uqtFixture() { obj.SetFirstName("Jack"); obj.SetSurName("Jones"); } MyClass obj; }; uqtTESTF(GetFullName) { uqtASSERT(rbEQUAL("Jack Jones", obj.GetFullName())); } }
If a fixture has a constructor with arguments, you can use that constructor by using the macro uqtTESTF_PARAM instead of uqtTESTF:
#include "uquonitest/Test.hpp" #include "MyClass.hpp" uqtTEST_GROUP(MyClass) { class uqtFixture { public: uqtFixture() { } uqtFixture(const std::string & firstname, const std::string & surname) { obj.SetFirstName(firstname); obj.SetSurName(surname); } MyClass obj; }; uqtTESTF_PARAM(GetFullName, ("Jack", "Jones")) { uqtASSERT(rbEQUAL("Jack Jones", obj.GetFullName())); } }