Is there a way in junit to test rowlocked exception?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you mock your database dependencies, then you can have your mock object throw the locked row exception.
As you’ll have removed your direct dependency on the database, the test should run faster, and you’d be less prone to “flickering tests” due to database problems such as the database not being a available or something similar.
Also, this way, you are only testing your code, and nothing to do with the database – it is implementation agnostic. Should you choose to change database vendor in the future, this (a) shouldn’t matter to your code and (b) your test doesn’t care what database it is using.
Some example mocking frameworks to get you started: