Assertions in If-Clauses in Unit Tests: Tips and Best Practices

https://8hob.io/posts/assertions-if-clauses-tests/

Generally, it is inadvisable to directly expect in if-clauses. Here are some tips to avoid these situations.

4 points · 2 comments · view on lemmy.world

2 Comments

kSPvhmTOlwvMd7Y7E@programming.dev · 1 pts · 1y (1 reply)

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!

8hob@programming.dev · 3 pts · 1y

The post talks about how to avoid ifs ;)