Getting Started — .NET
Install
Add Xcepto packages to your test project:
<PackageReference Include="Xcepto" Version="VERSION" />
<PackageReference Include="Xcepto.Rest" Version="VERSION" /> <!-- REST (JSON) adapter -->
<PackageReference Include="Xcepto.SSR" Version="VERSION" /> <!-- SSR adapter -->
Write a scenario
A Scenario specifies how to set up and tear down the system under test. Override Setup to register services and configure infrastructure:
public class MyScenario : XceptoScenario
{
public int Port { get; private set; }
protected override ScenarioSetup Setup(ScenarioSetupBuilder builder)
{
builder.Do(async _ =>
{
// start your service, assign Port, etc.
});
return builder.Build();
}
protected override ScenarioCleanup Cleanup(ScenarioCleanupBuilder builder)
{
builder.Do(_ => { /* stop service */ });
return builder.Build();
}
}
See Scenario for the full lifecycle.
Write your first test
XceptoTest.Given compiles a sequence of adapter calls into a state machine and runs it:
[Test]
public async Task ShipmentIsAccepted()
{
var scenario = new MyScenario();
var amount = 50;
await XceptoTest.Given(scenario, builder =>
{
var rest = builder.RestAdapterBuilder()
.WithBaseUrl(new Uri($"http://localhost:{scenario.Port}"))
.Build();
rest.Post("/shipment/accept")
.WithRequestBody(() => new AcceptShipmentRequest(amount))
.WithResponseType<AcceptShipmentResponse>()
.AssertThatResponse(r => r.Amount == amount);
rest.Get("/inventory/stock")
.AssertSuccess()
.AssertThatResponseContentString(
body => body.Contains("\"replenished\":true"));
});
}
What happens at runtime:
scenario.Setupstarts your infrastructure.- The
builderlambda registers steps — no HTTP calls happen yet. - The state machine executes: POST runs once, GET retries until the assertion passes or the timeout expires.
scenario.Cleanuptears down infrastructure.
Configure a timeout
var timeout = new TimeoutConfig(
total: TimeSpan.FromSeconds(30),
test: TimeSpan.FromSeconds(25));
await XceptoTest.Given(scenario, timeout, builder =>
{
// ...
});
total covers setup + execution. test covers the state machine only. See Timeout & Failures.
Next steps
- Core Concepts → Mental Model — understand the state machine
- Adapters → REST — full REST adapter reference
- Adapters → SSR — server-side rendered HTML adapter
- Patterns → Test Structure — how to organize tests well