4 ms·
There is a single cause of all unit-testing difficulty that I have ever seen: isolation. Functionality must be isolated to be testable. Examples: * You don't
by jdmichal 8y ago
There is a single cause of all unit-testing difficulty that I have ever seen: isolation. Functionality must be isolated to be testable.
Examples:
* You don't isolate side-effects, such as file creation. Now you must execute file creation every time you execute that functionality. Even though (I assume) you are not interested in testing the file system, you are now implicitly testing it.
* You don't isolate external dependencies, such as requiring a database connection. Now you can't test without standing up a temporary database.
* You don't isolate logic, such as doing several complicated validations in sequence within a single functionality. Now in order to test any of the validations, you must also arrange to pass all the previous validations.