Skip to main content

Getting Started

Test specification happens according to the Given-When-Then pattern.

Mental model

Test steps are not immediately executed when called! They are compiled into a state machine, where transition depends on the specified conditions.

The states are linked in a chain:

[Start] -> [First] -> [Second] -> [Third] -> [Final]

The test passes, if the Final state was reached before a timeout.

Given

Xcepto.Given introduces a specification environment based on a scenario.

XceptoTest.Given(scenario, builder =>
{
// Declare test behaviour here
}

Scenario classes specify instructions to setup and prepare the system under test.

When (Actions)

Actions often require interfacing technologies. Official adapters can be used to integrate some popular ones.

XceptoTest.Given(scenario, builder =>
{
var rest = builder.RegisterAdapter(new XceptoRestAdapter());

// When
rest.PostRequest<SomeRequest, SomeResponse>(
"localhost:3000/", new SomeRequest(),
someReponse => someResponse.value > 1000);
}

Post requests in particular also enable response validation (so they are hybrid action/expectation).

Then (Expectations)

Expectations represent transition conditions.

RabbitMQ can be used to block transition until a certain kind of message is published.

XceptoTest.Given(scenario, builder =>
{
var rabbitMq = builder.RegisterAdapter(new XceptoRabbitMqAdapter(config));

// When some Action happens

// Then expect a certain response
rabbitMq.EventCondition<ResponseMessage>(
e => e.someValue == 1234);
}