4 𝐦𝐒𝐬𝐭𝐚𝐀𝐞𝐬 you are doing while Unit testing that you need to π’π“πŽπ right away:

Photo by Kai Pilger on Unsplash

4 𝐦𝐒𝐬𝐭𝐚𝐀𝐞𝐬 you are doing while Unit testing that you need to π’π“πŽπ right away:

Dec 7, 2022Β·

1 min read

Play this article

Mentoring

"Unit testing is an essential part of the software development process, and it can help ensure that your code is correct, reliable, and maintainable.”

Avoid using the anti-patterns mentioned below:

π‘Όπ’π’Šπ’• π’•π’†π’”π’•π’Šπ’π’ˆ π’‘π’“π’Šπ’—π’‚π’•π’† π’Žπ’†π’•π’‰π’π’…π’”:

Making private methods public just to enable unit testing is a big NO NO, because it couples tests to implementation and, ultimately, makes the tests fragile.

π‘¬π’™π’‘π’π’”π’Šπ’π’ˆ π’‘π’“π’Šπ’—π’‚π’•π’† 𝒔𝒕𝒂𝒕𝒆 𝒕𝒐 𝒆𝒏𝒂𝒃𝒍𝒆 π’–π’π’Šπ’• π’•π’†π’”π’•π’Šπ’π’ˆ:

Don’t expose state that you would otherwise keep private for the sole purpose of unit testing. Your tests should interact with the system under test exactly the same way as the production code; they shouldn’t have any special privileges.

π‘Άπ’—π’†π’“π’–π’”π’Šπ’π’ˆ π’”π’•π’–π’ƒπ’ƒπ’Šπ’π’ˆ:

If you stub everything, you are testing a really small and simple and specific implementation detail. This will make your test fail almost instantly with a refactoring of a name or change in a serialisation method... Your tests will become unclear, brittle and less effective.

π‘³π’†π’‚π’Œπ’Šπ’π’ˆ π’…π’π’Žπ’‚π’Šπ’ π’Œπ’π’π’˜π’π’†π’…π’ˆπ’† 𝒕𝒐 𝒕𝒆𝒔𝒕𝒔:

Don’t imply any specific implementation when writing tests. Verify the code from a black-box perspective

Β