I built TestWire because once I finish a controller and need to write tests, if they're straightforward I just get bored writing them. I needed something that gives me a template based on my actual controller — not generic stubs, but ones shaped around my specific endpoints and dependencies. So TestWire reads your controller and generates test stubs based on it. You still write the real logic, it just handles the part that's purely mechanical.
For every controller TestWire finds, it produces a complete test project with:
- Integration tests — using
WebApplicationFactory<Program>for real HTTP calls - Happy path — a
200 OK/201 Createdtest that validates the response body - Auth test — a
401 Unauthorizedtest when[Authorize]is present - Auto-generated .csproj — includes all necessary NuGet packages for xUnit or NUnit
- Complex DTO support — generated request objects handle nested properties and collections
- Query & Header analysis —
[FromQuery]and[FromHeader]parameters are detected and integrated into tests
// Your controller (SampleApi/Controllers/ProductsController.cs)
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
private readonly IProductService _service;
public ProductsController(IProductService service)
{
_service = service;
}
[HttpGet("{id}")]
public async Task<ActionResult<ProductDto>> GetById(int id) { ... }
}// Generated by TestWire (xUnit example)
public class ProductsControllerTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly HttpClient _client;
public ProductsControllerTests(WebApplicationFactory<Program> factory)
{
_client = factory.CreateClient();
}
[Fact]
public async Task GetById_Returns200_WithProductDto()
{
var response = await _client.GetAsync("api/products/1");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ProductDto>();
Assert.NotNull(result);
}
}Requires .NET 8+
dotnet tool install -g testwiretestwire generate --project ./MyApi/MyApi.csprojScans your project and writes a full test project to ./MyApi.Tests/ by default.
testwire generate --project ./MyApi/MyApi.csproj --output ./teststestwire generate --project ./MyApi/MyApi.csproj --dry-runtestwire generate --project ./MyApi/MyApi.csproj --framework nunit| Flag | Description | Default |
|---|---|---|
--project |
Path to the .csproj file (required) |
— |
--output |
Directory to write generated test files | {ProjectName}.Tests |
--framework |
Test framework: xunit or nunit |
xunit |
--dry-run |
Print output to console, don't write files | false |
--report |
Generate a testwire-report.md summary |
false |
See CHANGELOG.md for the full history of changes.
This is an early release. Here's what's not supported yet:
- No
--controllerflag to target a single controller - Mocking for internal service calls within integration tests (coming in v0.3)
If any of these block you, please open an issue.
PRs and issues are welcome. Open an issue to discuss what you'd like to change before submitting a PR.
MIT © Mazen Hassan