3.64Enabling Assertions

Created on Aug 17, 2026~2 min read

When developing or writing unit tests and integration tests, we often need to verify whether the request content and response results meet expectations; this process is usually called "assertion". Assertions fall into two categories:

  • Request assertions: executed after building the HttpRequestMessage and before sending it, used to validate the request's URI, method, headers, body, and so on. If they fail, the request is not sent.
  • Response assertions: executed after receiving the HttpResponseMessage, used to validate the status code, response headers, response body, elapsed time, and so on.

If an assertion fails, the system throws an HttpAssertionException.

To enable assertions, call the UseAssertions() method and use it together with the Asserts(configure) method:

cs
HttpRequestBuilder.Get("https://furion.net")    .UseAssertions();HttpRequestBuilder.Get("https://furion.net")    .UseAssertions(false);   // Disable assertions