📄️ Installing TUnit
First create an empty .NET console application:
📄️ Writing your first test
Start by creating a new class:
📄️ Running your tests
As TUnit is built on-top of the newer Microsoft.Testing.Platform, and combined with the fact that TUnit tests are source generated, running your tests is available in a variety of ways.
📄️ Data Driven Tests
It's common to want to repeat tests but pass in different values on each execution.
📄️ Injectable Class Data Source
The ClassDataSource attribute is used to instantiate and inject in new classes as parameters to your tests and/or test classes.
📄️ Method Data Sources
A limitation of passing data in with [Arguments(...)] is that the data must be constant values. For example, we can't new up an object and pass it into this attribute as an argument. This is a constraint of the language and we can't change that.
📄️ Matrix Tests
Combinative tests can take multiple values for different arguments, and then generate every possible combination of all of those arguments.
📄️ Things to know
TUnit has made some decisions by design. You may need to know about them:
📄️ Libraries
If you want a library package to define things like re-useable base classes with hooks etc, then you shouldn't use the main TUnit package - As this assumes your project is a test project and tries to build it as an executable etc.
📄️ Congratulations!
You have just learned the basics of writing a test in TUnit.