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 开发者_JS百科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.
精彩评论