jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <li...@ehatchersolutions.com>
Subject Re: Is it possible to test for exceptions?
Date Wed, 11 Dec 2002 09:53:14 GMT
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:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message