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. To use Visual Studio’s output format, change the method to look like this:
int main()
{
VisualStudioResultsOutput output;
TestRunner runner(output);
return runner.Run();
}
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.
No comments