xUnit.net
Unit testing framework for .NET — uses [Fact] for parameterless tests, [Theory] with [InlineData] for parameterized tests, constructor injection for setup, and IDisposable/IAsyncDisposable for teardown. xUnit.net features: no [SetUp]/[TearDown] attributes (constructor/dispose pattern instead), [ClassFixture<T>] for shared expensive setup across tests in a class, [CollectionFixture<T>] for shared setup across test classes, Assert.Throws<T>, Assert.Equal with detailed diffs, and parallel test execution by default. Preferred over NUnit and MSTest for modern .NET projects — used by ASP.NET Core and Entity Framework Core test suites. Integrates with Moq/NSubstitute for mocking agent service dependencies.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Never include real agent credentials in test code — use test doubles and environment variables. Ensure agent test projects don't ship to production containers. Test databases should use separate credentials from production. Integration tests should not connect to production agent services.
⚡ Reliability
Best When
You're writing unit or integration tests for .NET agent services — xUnit's clean pattern (constructor setup, IDisposable teardown) and parallel execution make it the modern standard for .NET testing.
Avoid When
You need BDD-style Gherkin scenarios, your existing test suite uses NUnit (migration cost), or you need load/performance testing.
Use Cases
- • Agent service unit tests — [Fact] public async Task CreateAgent_WithValidInput_ReturnsAgentDto() tests CreateAgentCommandHandler in isolation with mocked dependencies using xUnit's clean constructor injection pattern
- • Parameterized agent validation tests — [Theory] [InlineData("", false)] [InlineData("valid-name", true)] public void ValidateName_ReturnsExpected(string name, bool expected) tests agent name validation across multiple inputs
- • Agent integration tests with WebApplicationFactory — [ClassFixture<AgentApiFactory>] shares test server across agent API integration tests; factory configures test database and DI overrides for agent endpoints
- • Async agent handler tests — [Fact] public async Task Handle_WhenAgentNotFound_ThrowsNotFoundException() with await Assert.ThrowsAsync<NotFoundException>(() => handler.Handle(cmd, CancellationToken.None)) tests async agent exceptions
- • Test output for agent debugging — ITestOutputHelper injected via constructor; _output.WriteLine($"Agent created: {agent.Id}") writes to test output visible in IDE test runner for agent test debugging
Not For
- • BDD-style tests — xUnit uses [Fact]/[Theory] attribute style; for Given/When/Then agent test scenarios readable by non-developers, use SpecFlow (Gherkin) or use xUnit with FluentAssertions
- • Integration tests requiring database isolation — xUnit tests run in parallel by default; database integration tests need explicit collection-based parallelism control or Respawn for database cleanup between agent tests
- • Load or performance testing — xUnit is functional test framework; use k6, NBomber, or BenchmarkDotNet for agent performance testing
Interface
Authentication
Testing framework — no auth concepts.
Pricing
xUnit.net is Apache 2.0 licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ No [SetUp]/[TearDown] — xUnit uses constructor for setup and IDisposable.Dispose for teardown; tests expecting [SetUp] from NUnit or MSTest experience method-not-recognized errors; migrate agent test setup to constructor and cleanup to Dispose or DisposeAsync
- ⚠ Test parallelism can cause database conflicts — xUnit runs test classes in parallel by default; agent integration tests sharing a database cause race conditions and test order dependencies; use [Collection] attribute to group agent database tests into single non-parallel collection or use Respawn to isolate each test
- ⚠ IClassFixture vs ICollectionFixture scope — IClassFixture<T> creates fixture once per test class; ICollectionFixture<T> creates once per [Collection] across classes; agent integration tests needing shared WebApplicationFactory should use ICollectionFixture to avoid creating multiple test servers
- ⚠ async void test methods are not awaited — [Fact] public async void TestAsync() runs but exceptions are not caught by xUnit; use async Task for all async agent tests; async void tests appear to pass even when throwing exceptions causing false positive agent test results
- ⚠ [Theory] with complex objects requires [MemberData] — [InlineData] only accepts compile-time constants (primitives, strings, Type); for agent test scenarios with complex objects (AgentConfig), use [MemberData(nameof(GetAgentTestCases))] with IEnumerable<object[]> property or method
- ⚠ Test output only visible on test failure by default — ITestOutputHelper messages are captured but only displayed when test fails; to always show agent debug output, run with dotnet test --logger 'console;verbosity=detailed'; IDE test runners show output in test detail pane regardless of pass/fail status
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for xUnit.net.
Scores are editorial opinions as of 2026-03-06.