DotHttpTest 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotHttpTest --version 1.0.7                
NuGet\Install-Package DotHttpTest -Version 1.0.7                
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="DotHttpTest" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotHttpTest --version 1.0.7                
#r "nuget: DotHttpTest, 1.0.7"                
#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.
// Install DotHttpTest as a Cake Addin
#addin nuget:?package=DotHttpTest&version=1.0.7

// Install DotHttpTest as a Cake Tool
#tool nuget:?package=DotHttpTest&version=1.0.7                

dothttptest

.NET Test Framework for API tests with .http files

Why another HTTP test framework?

I like .http files. They make development and debugging easy. With integration in VS Code, Visual Studio and Rider I like that I don't have to leave my editor to run them.

They are simple and efficient. Can be shared within the development team. They can be shared with a QA team.

As a developer, I also don't like duplicating work. I was searching for a test framework where I can re-use my .http files for API testing, but I didn't find anything that allowed me to do it using C#.

Extensions in .http file

dothttptest supports extensions in the form of .http file comments, allowing the same file to be used within existing tools without breaking compliance, while also allowing automating tests with the same file. All extensions including those that add verification checks are added as instructions within a comment similarily to how some .http formats allow setting a name for a request:

# @name MyRequestName
GET http://localhost/get HTTP/1.1

Verification checks within .http files

A verification check can be added in a similar way to @name by using the @verify command:

# @verify http status-code 200
GET http://localhost/get HTTP/1.1

The @verify command is followed by the module performing the verification. Additional modules can be added to support additional checks.

Verifiers can be created in code:

[ResponseVerifier("myVerifier")]
public class MyVerifier : IVerifier
{
	public void Verify(DotHttpResponse response, VerificationCheckResult result)
	{
		// ...
	}
}

.. and used within the .http file by speciying the same name as was specified in code on the ResponseVerifier attribute on the class.

Verify that an HTTP header exists in the response
# @verify header content-type exists
GET http://localhost/get HTTP/1.1
Verify that an HTTP header value exists in a response
# @verify header accept-ranges == bytes
GET http://localhost/get HTTP/1.1

Usage

CLI Example Usage

$ dothttp run <httpfile>

CLI will run the requests specified in the .http and generate a junit-xml as output.

Adding .NET package

Add package using .NET CLI
dotnet add package DotHttpTest

C# Example Usage

Running all requests in a .http file and getting the result
using DotHttpTest;

var runner = new TestPlanRunnerOptionsBuilder()
		.LoadHttpFile(pathToHttpFile)
        .Build();

var testStatus = await runner.RunAsync();
Console.WriteLine($"Requests failed: {testStatus.HttpRequestFails.Value} / {testStatus.HttpRequests.Value}");
Running a single request
using DotHttpTest;
using var client = new DotHttpClient();
var requests = client.LoadFile("testfile.http");
var request = requests.First();

var response = await client.SendAsync(request);

System.Net.Http.HttpResponseMessage httpResponse = response.AsHttpResponseMessage();
Console.WriteLine($"{httpResponse.IsSuccessStatusCode}");

Running stress, soak and iterative tests

dothttptest implements stress and soak inspired by K6. Stages can be defined on a request including concurrency (virtual users) and a duration.

# @stage ramp-up   duration:20s target:10
# @stage main      duration:10m target:10
# @stage ramp-down duration:20s target:0
GET http://localhost/get HTTP/1.1
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.5 132 7/1/2024
2.0.4 97 7/1/2024
2.0.3 96 6/28/2024
2.0.2 94 6/28/2024
2.0.1 94 6/28/2024
2.0.0 97 6/28/2024
1.5.2 98 6/28/2024
1.5.0 94 6/28/2024
1.4.0 137 3/15/2024
1.3.6 125 3/14/2024
1.3.5 116 3/8/2024
1.3.4 121 3/8/2024
1.3.3 114 3/8/2024
1.3.2 114 3/8/2024
1.3.1 109 3/7/2024
1.3.0 106 3/7/2024
1.2.8 103 3/7/2024
1.2.7 107 3/7/2024
1.2.6 119 2/20/2024
1.2.5 114 2/20/2024
1.2.4 247 12/5/2023
1.2.3 133 12/4/2023
1.2.2 134 12/4/2023
1.2.1 152 12/4/2023
1.2.0 152 12/1/2023
1.1.0 179 8/21/2023
1.0.11 155 8/21/2023
1.0.10 154 8/21/2023
1.0.9 161 8/21/2023
1.0.8 153 8/21/2023
1.0.7 160 6/16/2023
1.0.6 168 6/12/2023
1.0.5 158 6/12/2023
1.0.4 157 6/11/2023
1.0.3 164 6/11/2023
1.0.2 170 6/11/2023
1.0.1 145 6/11/2023
1.0.0 144 6/11/2023