DEV Community


Discussion on: A Series of My Unfortunate Mistakes (When Writing Tests)

joeyhub profile image
Joey Hernández • Edited

5 is a tricky one. I notice a lot of people doing this. It's not just a matter of trust but learning as well. Often people are testing their own understanding of how the library works to see if that's correct. People should be encouraged to experiment more in the interactive shell. You will always have a small amount of tests like this. I'm fairly experienced but there's always new things where assertions need to be tested.

There's a special case because some libraries can't necessarily be trusted, especially if you allow plugging in libraries or you're based on something that can have multiple implementations.

There are some libraries where you really do have to check to see if the ground is still beneath your feet. In one library on and off I've found it says it succeeded in doing something such as filling a database table but if you actually check to see if it really did that and if the thing is really in the database you find that it's not which turns out to be due to one library, somewhere, buried in layers of libraries and about 5 million lines of library to kernel driver code doesn't behave properly according to standards.

Not many people are in that situation, usually you make your software for a controlled environment so as to not have so many variable dependencies. Where you do have more variable host dependencies things can sometimes become very interesting. You then do start thinking of making a test suite to assert what you expect from your dependencies or better yet take them from a one good dependency that made tests that allow you to swap out implementation.