You should avoid complexity in your test at all costs. A few lines of straightforward workflow should be enough for arrange, act, and assert.
This means that we disallow the following in our tests:
Conditional statements such as
if
,match
, andfunction
Looping constructs such as
while
,for
Additional types, interfaces, discriminated unions, or classes apart from the SU.
Threads
Exception handling, except asserting for thrown exceptions
Manipulation of lists, sequences, maps, or tuples
In short, your test should be as simple as the following steps:
Set up the prerequisites to run the test.
Run the test.
Assert the result.
If anything else is needed, you probably have a too complex system that needs refactoring in order to bring down the complexity of your tests. Complexity in your tests will hurt you in several different ways. The most common is that your test will fail even before touching the SUT because the initialization logic assumes conditions of the SUT that might change...