简体   繁体   中英

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 procedures 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM