Can you please enter an issue in JIRA for this so I don't forget to make the change?
http://issues.appfuse.org Thanks! Matt On Thu, Feb 25, 2010 at 11:15 AM, Ted Bergeron <tedb...@triview.com> wrote: > I use the JUnit 4 annotations as well. The specific problem is as coded, > this test will pass when any of the lines throw the expected exception. You > want the final line to throw the exception, but if your code breaks and the > remove method starts throwing this exception, this test will pass. In that > scenario, you'd want this test to fail. > > Current code: > > @Test > @ExpectedException(DataAccessException.class) > public void testAddAndRemovePerson() throws Exception { > Person person = new Person(); > person.setFirstName("Country"); > person.setLastName("Bry"); > > person = personDao.save(person); > flush(); > > person = personDao.get(person.getId()); > > assertEquals("Country", person.getFirstName()); > assertNotNull(person.getId()); > > log.debug("removing person..."); > > personDao.remove(person.getId()); > flush(); > > // should throw DataAccessException > personDao.get(person.getId()); > } > > Suggestion: > > @Test > @ExpectedException(DataAccessException.class) > public void testAddAndRemovePerson() throws Exception { > Person person = new Person(); > person.setFirstName("Country"); > person.setLastName("Bry"); > > try { > > person = personDao.save(person); > flush(); > > person = personDao.get(person.getId()); > > assertEquals("Country", person.getFirstName()); > assertNotNull(person.getId()); > > log.debug("removing person..."); > > personDao.remove(person.getId()); > flush(); > > } catch (DataAccessException e) { > fail( ... ); > } > > // should throw DataAccessException > personDao.get(person.getId()); > } > > Now, the test generates the expected exception in only the 1 place where you > want it to. If other methods start throwing the exception, the test would > now fail. > ________________________________ > View this message in context: Re: Integration Tests > Sent from the AppFuse - User mailing list archive at Nabble.com. > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net For additional commands, e-mail: users-h...@appfuse.dev.java.net