Benchmarks
These benchmarks compare the happy-path overhead of aweXpect.Web (passing assertions, the dominant case in a healthy test suite) against the equivalent FluentAssertions calls.
- Suite:
HappyCaseBenchmarksdriven by BenchmarkDotNet. - Job:
MediumRunwith the in-process toolchain. - Runner:
ubuntu-latestGitHub Actions agent, refreshed on every push tomain. - FluentAssertions has no expectations on
HttpResponseMessageorUri, so its benchmarks do what a FluentAssertions user writes instead, e.g. read the content as astring. - Each tab shows the latest measured time and allocated memory; bars are scaled within the row so length corresponds to magnitude. Lower is better.
- Status code
- Header
- Content
- Problem details
- Request
- Query parameter
Verifies that the response has a success status code.
FluentAssertions verifies IsSuccessStatusCode.
await That(_response).HasStatusCode().Success();
_response.IsSuccessStatusCode.Should().BeTrue();
Verifies that the response has a header with the expected value. FluentAssertions verifies that the header has a single value which is equal to the expected one.
await That(_response).HasHeader("x-vendor").WithValue("VENDOR");
_response.Headers.GetValues("x-vendor").Should().ContainSingle().Which.Should().Be("VENDOR");
Verifies that the response has the expected content.
FluentAssertions reads the content as a string.
await That(_response).HasContent("response-bar");
(await _response.Content.ReadAsStringAsync()).Should().Be("response-bar");
Verifies that the response has a problem details content with the expected type, title and status.
FluentAssertions reads the content as a string, parses it into a JsonNode and compares it with an anonymous object.
await That(_problemResponse)
.HasProblemDetailsContent("https://httpstatuses.com/404")
.WithTitle("Track not found")
.WithStatus(404);
JsonNode.Parse(await _problemResponse.Content.ReadAsStringAsync()).Should().BeEquivalentTo(new
{
type = "https://httpstatuses.com/404",
title = "Track not found",
status = 404,
});
Verifies the method and the URI of the request that led to the response.
FluentAssertions compares the Method and the RequestUri of the RequestMessage.
await That(_response).HasRequestMessage(request => request
.HasMethod(HttpMethod.Get).And
.HasRequestUri("https://music.example.com/tracks/1"));
_response.RequestMessage.Should().NotBeNull();
_response.RequestMessage!.Method.Should().Be(HttpMethod.Get);
_response.RequestMessage.RequestUri.Should().Be(new Uri("https://music.example.com/tracks/1"));
Verifies that a Uri has a query parameter with the expected value.
FluentAssertions parses the query with HttpUtility.ParseQueryString and verifies the value of the parameter.
await That(_uri).HasQueryParameter("page").WithValue("2");
HttpUtility.ParseQueryString(_uri.Query)["page"].Should().Be("2");