By Developers, For Developers

Historical errata for Pragmatic Unit Testing in Java with JUnit

PDF PgPaper PgTypeDescriptionFixed onComments
66SUGGEST

“minutes” should be “seconds”

2005-11-24
66SUGGEST

missing “as” top of 2nd para

2005-11-24
1010SUGGEST

Top of page, typo: “it’s source” should be “its source”

2005-11-24
1212SUGGEST

5th para, “you application’s” should be “your application’s.”

2005-11-24
1616SUGGEST

First code example shouldn’t have largest at end

2005-11-24
1717SUGGEST

Last paragraph, “edges occur when when”: remove extra “when”

2005-11-24
1818SUGGEST

First paragraph, “the the” should be “to the”

2005-11-24
2020SUGGEST

In the first line of the first paragraph the second “by” should be removed

2005-11-24
2020SUGGEST

Assignment to max should be MIN_VALUE to reflect change on previous page.

2005-11-24
2222SUGGEST

First bullet point should be “Set up”, not “Setup”

2005-11-24
2323SUGGEST

First sentence in second paragraph should start “All of the following …”

2005-11-24
3030SUGGEST

In the code sample: NULL should be null

2005-11-24
3535SUGGEST

In line 6 of the second paragraph of section 3.7: “all you need do”, missing “to”

2005-11-24
4040SUGGEST

“tan” should be “than”

2005-11-24
4040SUGGEST

Expected value of “0” should be “9” in the data file, line 17

2005-11-24
4545SUGGEST

Initialization of “f” should be “filter”

2005-11-24
5953SUGGEST

2nd paragraph, “Stack” should be “MyStack”

2005-11-24
5354SUGGEST

Last paragraph, line 3: “you need test” should be “you need to test”

2005-11-24
6061SUGGEST

First line of exercise 2: Remove one “add”

2005-11-24
7577SUGGEST

Order of expected, actual is reversed in the test for ex. 7

2005-11-24
7880SUGGEST

Added reference to AntHill

2005-11-24
8385SUGGEST

Last paragraph, line 4: “would reasonable” should be “would be reasonable”

2005-11-24
10188SUGGEST

5th paragraph, “mislead” should be “misled”

2005-11-24
9193SUGGEST

3rd paragraph, line 4: Replace “is” by “it”

2005-11-24
9294SUGGEST

Last paragraph before section 8.3, line 9: Replace “too” by “two”

2005-11-24
115117SUGGEST

“int” types should be “double” in declaration of addCropMarks

2005-11-24
134123SUGGEST

3rd paragraph missing “be” in “there must a difference”

2005-11-24
61SUGGEST

Even in UTC, some days can be more than 24 hours. “Leap seconds” are added to keep UTC consistent with the motion of the earth.

2007-07-31
76DEFER

I was doing exercize 7 on page 76 and found that the tests do not cover pause. In fact, I left pause unimplemented and the tests pass. I suggest adding
assertFalse(mp3.isPlaying());
after line 69 in the test suite to ensure pause does what it ought to.

titleOK

My copy of the book says “Sixth Printing” on the back of the title page, which would make it P.6. However, the website only goes up to P.4—I suggest that you bring it up to date :)

2009-12-03
1SUGGEST

“prepared exclusively for Ren” misses the mark - I do not know Ren.

29TYPO

…don’t want TO TO include that…

53ERROR

In the description of the invariant for the MyStack class the authors write “However we manipulate the index variable next_index, one thing is supposed to be always true: (next_index >= 0 && next_index < stack.length).”

The upper bound of this condition is off by one, the condition should be: (… && next_index <= stack.length).

next_index is 0 when the stack is empty and is one larger than the index of the top element otherwise (its value could be used to represent the number of items on the stack). When the stack has 99 elements in it, next_index is 99. When the client pushes another element on to the stack, “stack[next_index] = aString;” puts the 100th value at index 99 and increments next_index to 100 (stack.length). This is a valid state for the stack to be in, and it should be allowed by the invariant. In this example, however, the authors’ invariant fails.

The same correction should be made to implementation of the checkInvariant method in the text, as well as in the MyStack.java file in code on the web site.

The following code sample illustrates the error:
public class Driver {
public static void main(String[] args) throws InvariantException {
MyStack s = new MyStack();

for (int i = 0; i < 100; ++i) {
s.push(Integer.toString(i));
s.checkInvariant();
}
}
}

The code produces:
Exception in thread “main” InvariantException: next_index out of range: 100 for stack length 100
at MyStack.checkInvariant(MyStack.java:38)
at Driver.main(Driver.java:7)

33SUGGEST

says: “It is usually a good idea to start off a new project by always inheriting from your own custom base class instead of the JUnit class”

This should be updated to the JUnit 4 best practice of using
@Test annotation instead of extending TestCase.

Page number is from printing 5 2006-03-20, but that’s not an option in the Version drop down.

Surprised there hasn’t been a new edition that matches JUnit 4.

Categories: