Testing external dependencies
When building unit tests, we talked about how it's based around the concept of isolating a unit in the code to test it independently.
This isolation concept is key, as we want to focus on small sections of the code to create small, clear tests. Creating small tests also helps in keeping the tests fast.
In our example above, we tested a purely functional function, parameter_tdd
, that had no dependencies. It was not using any external library or any other function. But inevitably, at some point, you'll need to test something that depends on something else.
The question in this case is should the other component be part of the test or not?
This is not an easy question to answer. Some developers think that all unit tests should be purely about a single function or method, and therefore, any dependency should not be part of the test. But, on a more practical level, there are sometimes pieces of code that form a unit that it's...