Adding Smarts to Our Stub: Verifying Parameters

Our Http stub always returns the same hardcoded JSON string, regardless of the latitude and longitude passed to its get() method. That’s a small hole in testing. If the AddressRetriever doesn’t pass the parameters correctly, we have a defect.

“How hard can it be to pass a couple arguments correctly to a function?” asks Pat. “Do we really need to test that?”

Dale says, “You’re forgetting when we shipped code the other week where someone inadvertently swapped the order of the latitude and longitude in another part of the system. We wasted a couple hours on that defect.”

Here’s another way to think about what we’re doing: we’re not exercising the real behavior of HttpImpl, but we know that other ...

Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.