Fluent REST API testing.
O.Get("api.example.com/widgets")
.Is.OK();O.Get("api.example.com/widgets/1")
.Is.NotFound();var widget = new
{
Name = "Super Widget"
};
O.Put("api.example.com/widgets/1")
.With.Json(widget)
.Has.Status(201);O.Delete("api.example.com/widgets/1")
.Is.Unauthorized();O.Delete("api.example.com/widgets/1")
.With.Authorization("Bearer", "xWd3jyM7")
.Is.Not.Unauthorized();You can use any unit testing framework including xUnit.net, NUnit, and MSTest. This example uses xUnit.net.
- Create a new test project.
dotnet new xunit- Install the NuGet package into your application.
dotnet add package Omicron- Add the following method to the generated
UnitTest1.cs, substituting<some-url>for your REST API endpoint.
[Fact]
public void GetSomeUrlReturns200OK()
{
O.Get("<some-url>")
.Is.OK();
}- Run the test with
dotnet testIf <some-url> returns status code 200 for a GET request then the test will succeed, otherwise it will fail with an
appropriate error message.