Programming foundations

Stage 6 · Lesson 6 of 8

Tests with xUnit

Build and ship your first projects

is a common .NET test . Create a test project with dotnet new xunit, reference your core , and run everything with dotnet test. A [Fact] is a single test.

A [Theory] with [InlineData(...)] rows runs one test over many inputs. Assertions read clearly: Assert.Equal(42.5m, ledger.MonthlyTotal()), Assert.Throws<ArgumentException>(() => Parse("abc")), and Assert.Equal(expected, actual, precision) for doubles, where the precision allows for tiny rounding differences.

Test the core logic in the , with no files or network inside, and cover such as an empty list and invalid values. Name tests after behaviour, such as RejectsNegativeAmounts, so a failure explains itself.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?