Skip to content
ballmüllersolutions logo Send an email Call us
November 27, 2026

Unit test

A unit test checks a small unit of code, usually a method, separately from the rest of the application. It runs in milliseconds, and when it fails, it points to the spot that is broken.

A unit test takes a small unit of an application, usually a method, detaches it from the rest of the code, and checks whether it behaves as expected. When it fails, it points to the spot where the error lies.

How it is built in .NET

In .NET, you usually write unit tests with xUnit.net. [Fact] marks a test, [Theory] with [InlineData] a test that runs with several inputs. dotnet test starts them all. Microsoft's guide names the same three parts for almost every test, the arrange, act, assert pattern:

[Theory]
[InlineData("", 0)]
[InlineData(",", 0)]
public void Add_EmptyEntries_ReturnsZero(string input, int expected)
{
    // Arrange
    var calculator = new StringCalculator();

    // Act
    var actual = calculator.Add(input);

    // Assert
    Assert.Equal(expected, actual);
}

The name states the method, the situation, and the expected behavior. Whoever reads a list of tests sees from it what the application is to be able to do. There is only one call in the "act" part per test. Then it is clear which case is affected when it fails.

What makes a good unit test

Unit tests protect against regressions, that is, against something that worked breaking through a change. But they do not replace integration tests: they do not see whether registration, configuration, and the database work together. Related are test-driven development, which works with such tests, and quality assurance as a whole.

An example from the Kladde

The rule for free times in the public booking is the most important rule of the Kladde. It combines opening hours, appointment length, lead time, lunch break, and times taken, and needs neither a server nor a database for it. In the course, you test it at all boundaries, including the days around the daylight saving time change, and stop the clock in the test for that. The tests for it run in milliseconds.

In the course

You learn the basics in K1, module 1.8: Why tests and Good tests. In K2, module 2.7 (testing on the web), follow Unit tests for rules and endpoints and the next level, Integration tests with WebApplicationFactory.

Further reading on the blog

Sources