Chapter 4. Unit testing with xUnit

This chapter covers

  • Executing unit tests with the .NET CLI
  • Writing unit tests with xUnit
  • The difference between facts and theories
  • Logging test output

Testing is an essential part of writing great libraries and applications, and the first line of defense for testing is the unit test. In this chapter you’ll learn how to write unit tests in .NET Core, execute the tests, and add and collect logging data.

4.1. Why write unit tests?

Unit tests are written against the smallest units in a software library, such as classes. A class should have responsibility over a single piece of functionality, and that responsibility should be entirely encapsulated by the class. This is the single responsibility principle, and ...

Get .NET Core in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.