juniortesting
[Fact] — a single test without parameters. [Theory] + [InlineData] — a parameterized test with multiple data sets.
xUnit is the standard for .NET. [Fact]: one scenario. [Theory]: one test with different data. [InlineData]: inline parameters. [MemberData]: data from a method/property. [ClassData]: data from a separate class. Constructor = setup, IDisposable = teardown. IClassFixture<T> — shared state between tests in a class. ICollectionFixture<T> — shared between collections.
[Fact]
public void Add_TwoNumbers_ReturnsSum()
{
var calc = new Calculator();
Assert.Equal(5, calc.Add(2, 3));
}
[Theory]
[InlineData(0, 0, 0)]
[InlineData(-1, 1, 0)]
[InlineData(int.MaxValue, 1, int.MinValue)] // overflow
public void Add_WithData_ReturnsExpected(int a, int b, int expected)
{
Assert.Equal(expected, new Calculator().Add(a, b));
}
[Theory]
[MemberData(nameof(GetTestCases))]
public void Process_WithCases_Works(Order order, bool expected) { ... }
public static IEnumerable<object[]> GetTestCases() { ... }When yes
Fact for specific scenarios. Theory for edge cases and boundary values
Interview tip
xUnit creates a new class instance for every test — no shared state between Fact/Theory.