3 ms·
Unit tests can verify assumptions that the implementation is internally relying on. E.g., say a greedy algorithm relies on a collection being sorted, even thoug
by prodigal_erik 11y ago
Unit tests can verify assumptions that the implementation is internally relying on. E.g., say a greedy algorithm relies on a collection being sorted, even though the public interface does not return results in any particular order. If I make a mistake such that an edge case leaves the collection not sorted correctly, a test of the public API can't tell unless it happens to trigger the edge case whose importance might not be obvious.
- kazinator 11y ago> a test of the public API can't tell unless ... "Can't tell unless" means exactly the same thing as "can tell". You have a way to get to that corner case through the public functionality. If there really is no way to tell through the current public API, there the bug doesn't exist.
- prodigal_erik 11y agoI think I'm arguing for letting white-box unit tests make assertions about implementation details in a simple and clear way, rather than having to somehow devise a test using only the black-box API that happens to fail if the assertion doesn't hold. In other words, you can only guarantee parts of the internal state are valid if you know how to infer them from outside. Are you arguing that all unit tests should be black-box?