Lately, I’ve been busy working on Igloo, which is a new unit testing framework for C++. It takes a lot of inspiration from NUnit. Both in the way you register test fixtures and test methods, and in the way that you write write your assertions.
After coming back to developing in C++ after working in .NET and Ruby for a while, I found myself really struggling with creating good, readable unit tests. In other environments I could write tests together with the product owner. Together, we could create and discuss tests that expressed what we wanted our code to do without getting buried in the details. The tests I wrote in C++ were quite unreadable for a non-C++ developer. This was largely due to the way the system we worked on was designed, but part of why we were struggling was the syntax of the unit testing frameworks in C++.
Igloo is an attempt to get back to the feeling of doing TDD in those other environments.
The following is a complete test application, written in Igloo:
#include <igloo/igloo.h>
using namespace igloo;
TestFixture(Assertions)
{
TestMethod(ShouldHandleIntegerAssertions)
{
Assert::That(5, !Equals(4));
}
TestMethod(ShouldHandleStrings)
{
Assert::That("joakim", Is().Not().EqualTo("harry"));
}
};
int main()
{
return TestRunner::RunAllTests();
}
There is still a lot of things that can be added to Igloo to make it more usable. If you have any feedback on what those things might be, I’d love to know.
Post a Comment