Branches and loops in unit test are tech debt.
General rule: unit test should have a cyclomatic complexity of one.
If of If-Else or Switch branches are a clear indicator that your test is bad one. It's clear that you are not testing one case, maybe your test setup is broken.
If you have catches (exception handling) this also mostly a indicator that you don't understand the code behavior. Don't mix this up with negative tests.
Loops are a little bit different, loops could be a indicator that your test setup is not optimal.
If you have higher cyclomatic complexity test you should try to refactor them. Have a look at parameterized tests, maybe it's the way to refactor your test.
No comments:
Post a Comment