|
FAQ entry critique (Re: Re: distinguishing between failures and errors): msg#00143java.junit.user
Comments inline. > Is this clearer? > > ---- > > Q: What's the difference between a failure and an error? > > A: > > Assertions are used to check for the possibility of failures, > therefore failures are anticipated. Errors are unanticipated > problems resulting in uncaught exceptions being propagated from a > JUnit test method. > > In the following example, the FileNotFoundException is expected and > checked with an assertion. If the expected exception is not raised, > then a failure is produced. If any other unexpected IOException or > unchecked exception (e.g. NullPointerException) is raised, the JUnit > framework catches the exception and signals an error. > > 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. ;) -- J. B. Rainsberger, President, Diaspar Software Services Let's write software that people understand. http://www.diasparsoftware.com/ telephone: +1 416 791-8603
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Re: distinguishing between failures and errors, Mike Clark |
|---|---|
| Next by Date: | Re: FAQ entry critique (Re: Re: distinguishing between failures and errors), Mike Clark |
| Previous by Thread: | Re: Re: distinguishing between failures and errors, Mike Clark |
| Next by Thread: | Re: FAQ entry critique (Re: Re: distinguishing between failures and errors), Mike Clark |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |