liveBook · Manning

Fact

As explained in ASP.NET Core in Action, 3e

Fact is an xUnit attribute identifying a parameterless method as an individual test case.

Fact is an xUnit attribute that marks a method as one individual test case. The test runner discovers the method and reports its assertions or failures. section 35.2 section 35.7

A Fact test method must follow these xUnit rules:

A simple Fact test

[Fact] public void ConvertToGbp_ConvertsCorrectly() { var converter = new CurrencyConverter(); var actual = converter.ConvertToGbp(3, 1.5m, 4); Assert.Equal(2, actual); } Use Fact when one fixed set of inputs represents one test case. Replace it with Theory when the method needs parameters and multiple data sets. section 35.5 section 35.5

Listing 35.2 An example xUnit unit test, created by the default template
public class UnitTest1       #1
{
    [Fact]                   #2
    public void Test1()      #3
    {
    }
}

Shows the default xUnit test shape: a public test class, a Fact attribute, and a parameterless test method. section 35.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines method and class restrictions, but does not descend into test-runner internals.
Examples
Uses CurrencyConverter tests for expected results and ArgumentException failures.
What you can do after
Apply it via xUnit to create discoverable tests and verify returned values or expected exceptions.
How it connects
Connects xUnit test methods with Theory, InlineData, assertions, and the .NET Test SDK.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.