This is normally done with a construct like this:

try {
  // stuff that causes expected exception
}
catch (...) {
  // expected
}
fail("did not get exception expected");




Matt Raible wrote:
Is it possible to test for exceptions?  I want to verify that an
exception is thrown when a user is not found - right now my test fails.

I'd love an assertException or something of that sort ;)

[junit] Testcase:
testGetUser(org.apache.persistence.ApplicationDAOHibernateTest):  Caused
an ERROR
[junit] org.apache.persistence.DAOException: User not found in database!
[junit] org.apache.persistence.DAOException:
org.apache.persistence.DAOException: User not found in database!
[junit]     at
org.apache.persistence.ApplicationDAOHibernate.getUser(ApplicationDAOHib
ernate.java:74)
[junit]     at
org.apache.persistence.ApplicationDAOHibernateTest.testGetUser(Applicati
onDAOHibernateTest.java:54)
[junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
[junit]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
[junit]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
[junit] Caused by: org.apache.persistence.DAOException: User not found
in database!
[junit]     at
org.apache.persistence.ApplicationDAOHibernate.getUser(ApplicationDAOHib
ernate.java:60)
[junit]     ... 15 more


[junit] TEST org.apache.persistence.ApplicationDAOHibernateTest FAILED

Thanks,

Matt


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to