O'Reilly logo

Pragmatic Unit Testing in Java 8 with JUnit by Jeff Langr, Andy Hunt, Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

COR[R]ECT: [R]eference

When testing a method, consider:

  • What it references outside its scope

  • What external dependencies it has

  • Whether it depends on the object being in a certain state

  • Any other conditions that must exist

A web app that displays a customer’s account history might require the customer to be logged on. The pop() method for a stack requires a nonempty stack. Shifting your car’s transmission from Drive to Park requires you to first stop—if your transmission allowed the shift while the car was moving, it’d likely deliver some hefty damage to your fine Geo Metro.

When you make assumptions about any state, you should verify that your code is reasonably well-behaved when those assumptions are not met. Imagine you’re developing the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required