The main method of the application should look as follows:

#include <igloo/igloo.h>
using namespace igloo;

int main()
{
  return TestRunner::RunAllTests();
}

This will automatically run all registered tests in the application.

Different Output Formats

The main function above will generate error output in Igloo’s default format. You can change how the result of a test run is reported by injecting a different outputter to the test runner.

Igloo comes with support for Visual Studio’s output format and the XML XUnit format used by, for instance, the Jenkins continuous integration server. You can also create your own outputter by inheriting from the TestResultsOutput class.

Visual Studio Output

To use Visual Studio’s output format, change the main function to look like this:

int main()
{
  VisualStudioResultsOutput output;
  TestRunner runner(output);
  return runner.Run();
}

XUnit Output

To use the XUnit XML format, change the main function to look like this:

int main()
{
  XUnitResultsOutput output;
  TestRunner runner(output);
  return runner.Run();
}

Line Numbers in Error Messages

To include line numbers in your error messages you can use the AssertThat() macro instead of Assert::That() construct.

Contexts

Igloo considers a test application to be an executable specification of the application that’s under test. The test application contains one or more contexts that each describe a state of the application under test and a set of specifications for what should hold true in that context.

#include <igloo/igloo.h>
using namespace igloo;

Context(ANewlyStartedGame)
{
  Spec(ShouldHaveAnEmptyBoard)
  {
    Assert::That(game.Positions(), Has().All().EqualTo(EmptyPosition));
  } 

  Game game;
};

Nested Contexts

Igloo enables you to create nested contexts. The inner context inherits and augments the properties of the outer context. This is a powerful feature that lets you organize your contexts in a way that enables you to create just the right amount of setup for each context.

#include <igloo/igloo.h>
using namespace igloo;

Context(ANewlyStartedGame)
{
  Spec(ShouldHaveAnEmptyBoard)
  {
    Assert::That(game.Positions(), Has().All().EqualTo(EmptyPosition));
  }

  Context(PlayerOneIsSelectedToStart)
  {
    void SetUp()
    {
      Parent().game.Select(PlayerOne);
    }

    Spec(ItShouldBePlayerOnesTurn)
    {
      Assert::That(Parent().game.NextPlayer(), Equals(PlayerOne));
    }
  };  

  Game game;
};

The Parent() operation is used to access the context directly outside the current context.