Caffeinated Coder
Book an appointment
Lesson 22 · Advanced .NET

Unit testing

A unit test is a small method that calls one piece of code with known inputs and checks the result by itself. Follow one xUnit test through dotnet test: it arranges qty = 10 and price = 5, acts by calling Cart.Total, and asserts that the total is 45. A bug (qty > 10 instead of >= 10) returns 50, the Assert throws and the test goes red; after a one-character fix the same test goes green.

14 min10 steps5 questionsAdvanced
Fig 22 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.