testwire 0.1.2
dotnet tool install --global testwire --version 0.1.2
dotnet new tool-manifest
dotnet tool install --local testwire --version 0.1.2
#tool dotnet:?package=testwire&version=0.1.2
nuke :add-package testwire --version 0.1.2
<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 test file with:
- Happy path — a
200 OK/201 Createdtest with a valid request - Bad path — a
400 BadRequesttest with invalid inputs - Auth test — a
401 Unauthorizedtest when[Authorize]is present - Mocked constructor dependencies — every injected interface becomes a
Mock<T>via Moq - DTO stubs with real property values — generated from your actual models, not placeholders
// 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<IActionResult> GetById(int id) { ... }
[HttpPost]
[Authorize]
public async Task<IActionResult> Create([FromBody] CreateProductDto dto) { ... }
}
// Generated by TestWire
public class ProductsControllerTests
{
private readonly Mock<IProductService> _mockService = new();
private readonly ProductsController _sut;
public ProductsControllerTests()
{
_sut = new ProductsController(_mockService.Object);
}
[Fact]
public async Task GetById_ReturnsOk_WhenProductExists()
{
var result = await _sut.GetById(1);
result.Should().BeOfType<OkObjectResult>();
}
[Fact]
public async Task GetById_ReturnsBadRequest_WhenIdIsInvalid()
{
var result = await _sut.GetById(-1);
result.Should().BeOfType<BadRequestObjectResult>();
}
[Fact]
public async Task Create_ReturnsCreated_WhenRequestIsValid()
{
var dto = new CreateProductDto { Name = "TestName", Price = 1 };
var result = await _sut.Create(dto);
result.Should().BeOfType<CreatedAtActionResult>();
}
[Fact]
public async Task Create_ReturnsUnauthorized_WhenUserIsNotAuthenticated()
{
var result = await _sut.Create(new CreateProductDto());
result.Should().BeOfType<UnauthorizedResult>();
}
}
Installation
Requires .NET 8+
dotnet tool install -g testwire
Usage
Basic
testwire generate --project ./MyApi/MyApi.csproj
Scans your project and writes test files to ./TestWire.Generated/ 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 | ./TestWire.Generated |
--framework |
Test framework: xunit or nunit |
xunit |
--dry-run |
Print output to console, don't write files | false |
Changelog
See CHANGELOG.md for the full history of changes.
Current Limitations (v0.1.2)
This is an early release. Here's what's not supported yet:
[FromQuery]and[FromHeader]parameters are not yet analyzed- No
.csprojfile is generated for the output test folder — you need to add one manually - No
--controllerflag to target a single controller - Mock
.Setup(...)uses default behavior — explicit return values coming in v0.2
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 | 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. |
This package has no dependencies.