DEV Community

Discussion on: What dev topic do you think you should understand, but don't?

Collapse
 
rhymes profile image
rhymes

One good advice I can give you is to never test the library (unless you don't really trust it, but then you should probably change library :D).

So, if have a pure fuction that adds two numbers, your test should make sure that by giving 3 and 2 you get 5, maybe also test what happens with 0, negative numbers, floating numbers and if you want to feel sure, see how it behaves with something that's not a number (if you are operating with a loosely typed language).

If your function calls a database and a REST API the first thing you have to ask yourself is: am I here to test the database and the API or the function itself? I guess in this case you're trying to test the function. So DB and API should be black boxes in this case. You should stub those two, make the stubs return reasonable values and see what happens to your own function.