Skip to content

Igloo – Constraint Based Unit Testing in C++

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.

One Comment

  1. Josh Szepietowski wrote:

    Thanks so much for making this. It is very timely for me (in process of picking a framework for C++ testing at work).

    To put it simply, your syntax is absolutely beautiful.

    Do you have plans to add generator support? I would really like to specify a MSVC compatible output and an HTML ‘prettified’ output (either directly, or the result of a transformed XML output).

    Saturday, May 29, 2010 at 1:42 am | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*