Building unit tests
In this section, we will see different types of unit tests. We will begin by testing a static class, then we will write tests for a class with no dependencies. We will continue with a class with dependent services and learn how to mock these dependencies to unit test that class. We will learn the basics of writing automated test code with examples.
Let's begin with the simplest case—testing static classes.
Testing static classes
A static class with no state and external dependencies is the easiest class to test. EventUrlHelper
is a static class (in the EventHub.Domain
project of the EventHub solution) and is used to convert an event's title to a proper URL part. The following test class (in the EventHub.Domain.Tests
project of the EventHub solution) tests the EventUrlHelper
class:
public class EventUrlHelper_Tests { [Fact] public void Should_Convert_Title_To_Proper_Urls() &...