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 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>();
}
}Requires .NET 8+
dotnet tool install -g testwiretestwire generate --project ./MyApi/MyApi.csprojScans your project and writes test files to ./TestWire.Generated/ 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 | ./TestWire.Generated |
--framework |
Test framework: xunit or nunit |
xunit |
--dry-run |
Print output to console, don't write files | false |
See CHANGELOG.md for the full history of changes.
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.
PRs and issues are welcome. Open an issue to discuss what you'd like to change before submitting a PR.
MIT © Mazen Hassan