Skip to content

Snapshot Testing

Although Alba does not ship built-in snapshotting support, it does easily integrate with the popular Verify framework. Given Verify and Verify.AspNetCore has been added and initialized for your test framework of choice, you can pass the scenario to Verify(), and response data will be captured for a complete picture of your network request.

Given a test with the shape of:

cs
await using var host = await AlbaHost.For<global::Program>();

var scenario = await host.Scenario(s =>
{
    s.Post.Json(new MyEntity(Guid.NewGuid(), "SomeValue")).ToUrl("/json");
});

await Verify(scenario);

snippet source | anchor

Will result in a snapshot of:

json
{
  Context: {
    Request: {
      Headers: {
        Accept: application/json,
        Content-Length: 67,
        Content-Type: application/json,
        Host: localhost
      }
    },
    Response: {
      StatusCode: OK,
      Headers: {
        Content-Type: application/json; charset=utf-8
      },
      Value: {
        id: Guid_1,
        myValue: SomeValue
      }
    }
  }
}