Home

xUnit

[Fact] Attribute

The [Fact] attribute is used to indicate a method is a test.

[Theory] Attribute

The [Theory] attribute is used for parameterized tests that can run with multiple sets of data.

Example:

[Theory]
[InlineData(1, 2, 3)]
[InlineData(-1, 1, 0)]
public void Add_ShouldReturnSum_ForVariousInputs(int a, int b, int expected)
{
    // Arrange
    var calculator = new Calculator();

    // Act
    var result = calculator.Add(a, b);

    // Assert
    Assert.Equal(expected, result);
}