How to test methods in service layer calling a stored proc in java?
I am working on a legacy code where there are several methods with calls to Stored proce开发者_如何学JAVAdures from the service layer itself as opposed to hibernate. Is it possible to test those methods in any manner so that my code coverage can increase ? I am using java 1.5 and sql server 2005.
This sounds like a classic requirement for mocking. You would mock out the database connection and communication (via, perhaps, dependency injection) by supplying a mocked version of the objects that return static and consistent test data. As such you don't have to rely on the database connection (making your tests faster and more reliable).
Such frameworks exist for Java - check out JMock or EasyMock, for example.
精彩评论