Member-only story
.NET Core 101 Unit tests
To create functional, reliable applications
What Are Unit Tests?
The basic idea of unit tests was introduced by Kent Back in Smalltalk. Unit tests are among the best tools to increase software quality and are usually written in a particular test framework.
Simply put, a unit test is a piece of code that calls another piece of code (unit) and checks if the output matches the desired outcome.
In the most original definition, a unit was a method or a function. Today one also speaks of a unit of work, which is:
"[…] the sum of actions that take place between the invocation of a public method in the system and a single noticeable result by a test of that system."
(Chapter 1. “The basics of Unit Testing — The Art of Unit Testing" by Roy Osherove).
This means that a single software component or method is tested. Only code under the developer's complete control should be tested. However, according to Roy Osherove, author of “The Art of Unit Testing: With Examples in C#,” one should not try to minimize the size of a unit of work under test. If you try to reduce the size of a unit of work, you are faking things that are not a result for the user of a public API.
Further Types of Tests
Besides unit tests, there are many other tests. In the following, I would like to discuss the following standard tests: integration, functional, and acceptance tests.
Integration Tests
Unlike unit tests, integration tests are not self-sufficient. They usually have additional dependencies outside the system under tests, such as databases or a file system. The cooperation of two or more software components is tested. Integration tests can also involve infrastructure issues. Integration tests use actual dependencies, while unit tests isolate the unit of work from its dependencies.
Functional Tests
Functional tests are to be considered high-level testing. The functionality from…