logo       

FAQ entry critique (Re: Re: distinguishing between failures and errors): msg#00146

java.junit.user

Subject: FAQ entry critique (Re: Re: distinguishing between failures and errors)

--- In junit@xxxx, "J. B. Rainsberger" <jbr@xxxx> wrote:
> > public void testNonexistentFileRead() throws IOException {
> > try {
> >
> > File file = new File("doesNotExist.txt");
> > FileReader reader = new FileReader(file);
> > assertEquals('a', (char)reader.read());
> >
> > fail("Should have thrown FileNotFoundException");
>
> Suggestion: change the failure message to "Read from a nonexistent
> file?!". I prefer this pattern because it indicates what the system
> did incorrectly in a higher-level way. I also think it's funnier
> when I see it in the test results. ;)

excellent suggestion. i fall into the trap of the "should have thrown
XYZException" failure message too often. instead, since unit tests
should tell a story of what happened when the unit-under-test is
exercised in a particular way, they should explain the "what?" of
the failure rather than the "how?".

i like the new examples, except that i'd add some language to indicate
that the file "exists.txt" was hopefully created by the test class's
setUp(), so that the test can run without having to depend on someone
else having put the file in place.

--p






<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise