If you cannot see what the test is about at a glance, then it is too complex. The first thing you look at is the name of the test, which should tell you what the test is asserting, and the second is the implementation of the test, which should be a few lines of straightforward code.
The signs of a too complex test are as follows:
Large amount of setup code needed
Conditional logic, such as
if
,switch
, or null-coalescing operators are usedLooping constructs, such as
while
,for
, orforeach
are usedThe test needs helper functions or types to operate
It has more than one mock or stub
It requires mocking and stubbing more than one method or property
The test doesn't fit the screen without scrolling
When the test fails, the developer looking at the test might not be the same that wrote it from the start. This makes it imperative that the test itself is as straightforward as possible. Even more plausible, the developer looking at the test is not even very familiar with the system...