TestResponses 0.2.1

dotnet add package TestResponses --version 0.2.1
                    
NuGet\Install-Package TestResponses -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TestResponses" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TestResponses" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="TestResponses" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TestResponses --version 0.2.1
                    
#r "nuget: TestResponses, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TestResponses@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TestResponses&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=TestResponses&version=0.2.1
                    
Install as a Cake Tool

TestResponses

Readable, contextual API test responses for .NET

Overview

TestResponses is a set of HttpResponseMessage decorators that make API integration tests more readable and more informative, while keeping everything you need easy to access.

Here’s a plain HttpResponseMessage example:

var httpResponse = await _weatherApi.GetTodayWeather("Saratov");
httpResponse.EnsureSuccessStatusCode();
var dto = await httpResponse.Content.ReadFromJsonAsync<WeatherForecast>();

dto!.City.Should().Be("Saratov");

With TestResponses, test code becomes much simpler:

var response = await _weatherApi.GetTodayWeather("Saratov");

response.AsDto!.City.Should().Be("Saratov");
  • Less boilerplate
  • DTO model for happy paths
  • Raw HttpResponseMessage property for corner cases
  • Does not fail the test right away so you can test 4xx responses with the same object, without try-catch statement
  • But main value is in failure messages: Instead of a generic HttpRequestException, TestResponses shows response context, which makes it easier to understand the failure without debugging:
TestResponses.TestResponseAssertionException
Response status code is not 200
Status code: 400 (Bad Request)
Response:
{
  "type": "Validation",
  "title": "Request validation failed",
  "status": 400,
  "errors": {
    "date": ["'00000000-0000-0000-0000-000000000000' is not a valid date"]
  }
}

And it's not restricted to JSON responses, because TestResponses is a family of response types - from empty to JSON and files. They are also designed to be extensible and configurable, so you can create a type that fits your scenario, or modify behavior of existing one.

Get started

1. Install

dotnet add package TestResponses

2. Instantiate

Wrap the request task in a suitable TestResponse type with ReadAs:

public Task<TestJsonResponse<WeatherForecast>> GetTodayWeather(string city)
{
    return httpClient
        .GetAsync($"forecasts?city={city}&date=today")
        .ReadAs<TestJsonResponse<WeatherForecast>>(expectedStatusCode: 200);
}

3. Await and use

var response = await _weatherApi.GetTodayWeather("Saratov");

var statusCode = response.StatusCode;
var rawResponse = response.HttpResponse;
var dto = response.AsDto;

Documentation

For more information you can read the docs.
Docs →

Project also has usage examples with failing tests that you can run and play around with
Examples →

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 113 5/16/2026
0.2.0 102 5/4/2026
0.2.0-prerelease.2 64 5/1/2026
0.2.0-prerelease.1 62 4/22/2026
0.1.0 948 12/19/2025

## Changes

### Changed
- README.md has more details about what the library can do now

## Repo changes

- updated CI version pick to fail if desired version is already
published