📄️ Test Set Ups
Most setup for a test can be performed in the constructor (think setting up mocks, assigning fields.)
📄️ Test Clean Ups
TUnit supports having your test class implement IDisposable or IAsyncDisposable. These will be called after your test has finished executing. However, using the attributes below offers better support for running multiple methods, and without having to implement your own try/catch logic. Every [After] method will be run, and any exceptions will be lazily thrown afterwards.
📄️ Retrying
Unfortunately sometimes our tests hit issues. It could be a blip on the network, but that could cause our entire test suite to fail which is frustrating.
📄️ Repeating
If you want to repeat a test, add a [RepeatAttribute] onto your test method or class. This takes an int of how many times you'd like to repeat. Each repeat will show in the test explorer as a new test.
📄️ Timeouts
If you want to stop a test after a specified amount of time, add a [Timeout] attribute onto your test method or class. This takes an int of how many milliseconds a test can execute for.
📄️ Properties
Custom properties can be added to a test using the [PropertyAttribute].
📄️ Test Context
All tests have a TestContext object available to them.
📄️ Test Filters
Running TUnit via dotnet run supports test filters.
📄️ Explicit
If you want a test to only be run explicitly (and not part of all general tests) then you can add the [ExplicitAttribute].
📄️ Not in Parallel
By default, TUnit tests will run in parallel.
📄️ Depends On
A test can depend on another test. This means that your test will not start unless the other test has finished.
📄️ Ordering Tests
By default, TUnit tests will run in parallel. This means there is no order and it doesn't make sense to be able to control that.
📄️ Parallel Groups
Parallel Groups are an alternative parallel mechanism to [NotInParallel].
📄️ Parallel Limiter
TUnit allows the user to control the parallel limit on a test, class or assembly level.
📄️ Executors
In some advanced cases, you may need to control how a test or hook is executed.
📄️ Class Constructor Helpers
Some test suites might be more complex than others, and a user may want control over 'newing' up their test classes.
📄️ Command Line Flags
--diagnostic
📄️ Data Source Generators
TUnit exposes an abstract DataSourceGeneratorAttribute class that you can inherit from and implement your own logic for creating values.
📄️ Property Injection
TUnit makes it easy to initialise some properties on your test class instead of passing them into the constructor.
📄️ Attribute Event Subscribing
Custom attributes (and custom class constructor objects) applied to your tests can optionally implement the following interfaces: