views:

114

answers:

2

When running an integration test (Web Service talking to JDBC, in this case) how do you force the database to throw an error so that the resulting soap fault can be inspected?

I'm using Spring's Transactional Test Framework, so would be unreasonable to just issue a DROP TABLE whatever; to break it? :D

+1  A: 

In my experience, this is an excellent use for mock objects. Specifically cases where you need to cause a specific failure in order to test how your object, in the case of a unit test, or set of objects, in the case of integration tests, will handle a particular failure. It is better to be in complete control of the failure rather than forcing a specific case of the failure in your integration tests.

I recently worked with an entity framework where I encountered a similar dilemma. By creating mock objects for the entities I was able to force an exception to be thrown during on method calls while running certain tests in order to test failure conditions interacting with the database. This isn't an answer that deals with Spring's Transactional Framework, but I am sure the same principles apply.

Kevin
My unit tests cover what what can be mocked. This is a final test deployed on a QA environment to see that the whole lot plays together.
tunaranch
A: 

Would unplugging the database server's network cord be to much? That simulates "database dying" pretty well.

Justin Haygood
Yes, it would be too much, as there will be other things accessing it. (never you mind the fact that in my case we don't have access to the physical server infrastructure)
tunaranch