liveBook · Manning

Theory

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

Theory is an xUnit attribute that marks a parameterized test method executed once for each supplied data set.

Theory is an xUnit attribute for parameterized tests. It runs one test method repeatedly, using a different argument set each time, so related cases do not require duplicated methods. section 35.5

Supply arguments with one of these data providers:

  • [InlineData] places each complete argument set directly above the test method. section 35.5
  • [MemberData] reads test data from a static property on the test class. section 35.5
  • [ClassData] obtains test data from a separate class. section 35.5

Testing several currency conversions

Decorate ConvertToGbp_ConvertsCorrectly with [Theory] and three [InlineData] attributes: (0, 3, 0), (3, 1.5, 2), and (3.75, 2.5, 1.5). xUnit executes the method three times and reports three separate tests.

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

How deep it goes
Explains method decoration, argument sources, repeated execution, and separate test reporting without detailing runner internals.
Examples
Uses CurrencyConverter conversions with zero, ordinary, and fractional input cases.
What it assumes
Assumes an xUnit test project and basic assertions while teaching parameterized method arguments from the fundamentals.
What you can do after
Apply via xUnit to run one test method against multiple data sets and inspect each result separately.
How it connects
Connects parameterized testing with unit testing, assertions, InlineData, MemberData, ClassData, and Fact.

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.