Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unit tests localize failures more tightly. Integration-level tests more closely correspond to user requirements and so are better predictor of delivery success. Neither of them is much good unless built and maintained, but both of them are very valuable if properly used.</p> <hr> <p>(more...)</p> <p>The thing with units tests is that no integration level test can exercise all the code as much as a good set of unit tests can. Yes, that can mean that you have to refactor the tests somewhat, but in general your tests shouldn't depend on the internals so much. So, lets say for example that you have a single function to get a power of two. You describe it (as a formal methods guy, I'd claim you specify it)</p> <pre><code>long pow2(int p); // returns 2^p for 0 &lt;= p &lt;= 30 </code></pre> <p>Your test and your spec look essentially the same (this is sort of pseudo-xUnit for illustration):</p> <pre><code>assertEqual(1073741824,pow2(30); assertEqual(1, pow2(0)); assertException(domainError, pow2(-1)); assertException(domainError, pow2(31)); </code></pre> <p>Now your implementation can be a for loop with a multiple, and you can come along later and change that to a shift.</p> <p>If you change the implementation so that, say, it's returning 16 bits (remember that <code>sizeof(long)</code> is only guaranteed to be no less than <code>sizeof(short)</code>) then this tests will fail quickly. An integration-level test should probably fail, but not certainly, and it's just as likely as not to fail somewhere far downstream of the computation of <code>pow2(28)</code>.</p> <p>The point is that they really test for diferent situations. If you could build sufficiently details and extensive integration tests, you might be able to get the same level of coverage and degree of fine-grained testing, but it's probably hard to do at best, and the exponential state-space explosion will defeat you. By partitioning the state space using unit tests, the number of tests you need grows much less than exponentially.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload