December 2013
Intermediate to advanced
256 pages
6h 56m
English
Let’s consider the code in Listing 7-1.
Listing 7-1: A simple string composition function
public String describeAddition(int left, int right) { return "The sum of " + left + " and " + right + " is " + (left + right);}
While the example is trivial and a bit contrived, it is a fair representation of the way strings are commonly handled. How might we test such a method? Well, what do we know about the method? We know some fragments of the text, but those should not change from run to run. What we are probably most concerned with is that the correct values make it into the output. We might write a test like that in Listing 7-2.
Listing 7-2: A test for the code in Listing 7-1
Read now
Unlock full access