Chapter 2Getting Real with JUnit

In the last chapter we wrote tests against a simple example class named ScoreCollection that calculates an arithmetic mean. Working through that exercise helped us get a good handle on JUnit fundamentals.

Pat wasn’t impressed, however. “All that effort to test a tiny class that averages a bunch of numbers? Real code isn’t so simple.”

True, Pat, although the previous chapter was more about getting you comfortable with JUnit. We could write more tests against ScoreCollection, but it’s time to move on to testing code closer to the reality of the average system.

In this chapter we’ll spend a little time looking at a meatier bit of code that we want to test. The analysis effort will help us to focus on writing ...

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.