Igloo creates a new context before each call to a Spec. This ensures that each Spec is executed in a fresh environment. Sometimes you might need to perform additional setup before each call, and additional cleanup after each call. You can do this by overriding the methods SetUp and TearDown in your context.
#include <igloo/igloo.h>
using namespace igloo;
Context(NameOfContext)
{
void SetUp() { /* Setup code. Called before each Spec. */ }
void TearDown() { /* Tear down code. Called after each Spec. */ }
// ...
};
Context SetUp and TearDown
Sometimes you need to setup an environment that is the same for all specs in a context, and that takes a bit too long to setup before each call. In this case you can use Igloo’s SetUpContext and TearDownContext methods to set up static members used in the specs later on.
Context(NameOfContext)
{
static void SetUpContext() { /* Called once before any Spec. */ }
static void TearDownContext() { /* Called once after all Specs. */ }
// ...
static MyEnvironment common_stuff;
};
No comments