3 ms·
>That is, the only specification for how the system should work is how it worked yesterday. In that case, unit tests serve as a great specification. Unit tests
by crdoconnor 9y ago
>That is, the only specification for how the system should work is how it worked yesterday. In that case, unit tests serve as a great specification.
Unit tests are better than nothing, but integration tests usually serve as a better specification still.
Unit tests are ok at specifying low level side-effect-less modules though.
- mannykannot 9y agoYes, and furthermore, due to the combinatorial explosion, and as explained in the article, unit tests can only cover an infinitesimal fraction of all the possibilities at that level. The sort of interfaced-based testing favored in the article ameliorates the problem because it uses the inherent abstractions of the code to prune the problem space. In addition, if you depend on unit tests, you cannot tell if a change has broken the system - you can expand or rewrite your tests to cover the change (if we put aside the question of what requirements these tests are testing), but that cannot tell you if you have, for example, violated a system-wide constraint. Only testing at higher levels of abstraction, up to the complete-system level, can help you with that. Therefore, to the extent that the "the code is the specification" argument is a valid one, it actually leads to the conclusion that Coplien is right.
- ZenoArrow 9y agoIn my opinion, the way that most unit tests are written is mostly a waste of effort, but there are a class of unit tests that are much better suited to the task. The class of unit tests I'm referring to is property-based tests. The most famous property-based testing framework is QuickCheck, but there are plenty of others, e.g. FsCheck for C#/F#, ScalaCheck for Scala, Hypothesis for Python, etc... The general idea being that you write out a specification that the code should meet, and the test parameters are determined at runtime, rather than being hardcoded. There's more to it than that, but that's the general idea. If you want a simple introduction, I'd recommend this video: https://www.youtube.com/watch?v=AfaNEebCDos https://www.youtube.com/watch?v=AfaNEebCDos