In unit tests, assertions inside if-clauses risks being silently skipped. We discuss some tips and best practices in situations where assertions live in if-clauses.
Generally, it is inadvisable to directly expect in if-clauses. Here are some tips to avoid these situations.
Don’t write “if” in your tests! It makes very, very little sense: how is that, you test your application and you are unsure what is the resulting outcome of a call? Is it depending on arguments? Then fix the argument, and expect 1 specific result. Is it depending on environment? Fix/mock the environment.
Don’t write “if” in your tests! It makes very, very little sense: how is that, you test your application and you are unsure what is the resulting outcome of a call? Is it depending on arguments? Then fix the argument, and expect 1 specific result. Is it depending on environment? Fix/mock the environment.
No “ifs” in the tests!
The post talks about how to avoid ifs ;)