testwire 0.2.1
dotnet tool install --global testwire --version 0.2.1
dotnet new tool-manifest
dotnet tool install --local testwire --version 0.2.1
#tool dotnet:?package=testwire&version=0.2.1
nuke :add-package testwire --version 0.2.1
<div align="center">
🔌 TestWire
</div>
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.
What Gets Generated
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);
}
}
Installation
Requires .NET 8+
dotnet tool install -g testwire
Usage
Basic
testwire generate --project ./MyApi/MyApi.csproj
Scans your project and writes a full test project to ./MyApi.Tests/ by default.
Custom output directory
testwire generate --project ./MyApi/MyApi.csproj --output ./tests
Preview without writing files
testwire generate --project ./MyApi/MyApi.csproj --dry-run
Use NUnit instead of xUnit
testwire generate --project ./MyApi/MyApi.csproj --framework nunit
All Options
| 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 |
Changelog
See CHANGELOG.md for the full history of changes.
Current Limitations (v0.2.0)
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.
Contributing
PRs and issues are welcome. Open an issue to discuss what you'd like to change before submitting a PR.
License
MIT © Mazen Hassan
| Product | Versions 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 was computed. 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. |
This package has no dependencies.