简体   繁体   中英

Mocking a StoredProcedure

I am soon writing a unit test to a service tier-class that relies heavily to org.springframework.jdbc.object.StoredProcedure class. The service object is going to be simple batch class, reading data from a stored-procedure, aggregating it and sending it to a another stored-procedure.

What would be a best practice regarding such an unit test (since it relies heavily to a database). Should I use a fake object (set of method stubs), write a mock with a database backend or mirror the real thing (with the cost of keeping the infrastructure up to date)?

I want be as lazy as possible and still guarantee quality.

Personally, I would do the unit tests in a case like this with an embedded database like H2 .

Hope this helps.

I would not worry about testing end-to-end in this case. I would stub out the calls to the stored proc and make sure your code works as expected.

The next thing to do is test the stored proc. If you are on an oracle platform then you can test-drive the proc using ruby-plsql. I have used this on a project before and it works well. If you are not on an oracle platform then you are going to have to build something in your test harness that can call the stored proc in such ways that you will see the different outcomes. Just shoot for the happy path and a few edge cases.

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