1. 8
  1.  

  2. 2

    I really like this piece.

    1. 2

      The first bit is not quite true. If you cannot control X, but you can control not-X and you can sample X then you can measure X. Often, you can’t control X or all of not-X, and then you need to do more complicated statistics.

      1. 1

        The definitions of “stubbing” and “mocking” here are at odds with what I’ve seen elsewhere. Granted, the distinction is clear as mud to begin with, mostly because the same testing libraries do both things, but when I’ve seen authors try to use those terms with precision, the definitions have usually been along the lines of Martin Fowler’s breakdown.

        • Stubbing: Replacing a dependency with a test double that responds to the code under test in a predictable way that’s controlled by the test. Often the replacement will just return canned values.
        • Mocking: Everything in the “stubbing” definition, but in addition, the test double can itself be the subject of assertions: did the code under test pass such-and-such parameter to such-and-such function of the mock dependency? Did it call function A followed by function B?

        I actually can’t think of another time I’ve seen this article’s definition (stubbing = swapping out implementations of individual functions, mocking = replacing entire objects).