Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing JDBC queries in JUnit [closed]

I'm just wondering, what is the best way to test JDBC-related methods? Such as adding users, banning users, etc.

(Using JUnit)

Should I set all my void methods to booleans and have them return true if they've worked, false if they didn't, and assert those values accordingly in my JUnit tests?

This is just a general question to find the best practices.

Thank you!

like image 965
user2297666 Avatar asked Jun 19 '13 14:06

user2297666


1 Answers

I personally find an awesome tool for this is Mockito. You can mock what a JDBC return would give you so you can say given a specific query and parameter, you'd get a specific value back.

You should not have to modify your code to make it work with unit tests, it should work in both production and test exactly the same way.

You could also consider using an in memory database such as Derby and loading values at the start of your test phase so you know the values that exist in it. Mocking would probably be faster though in terms of execution time.

like image 56
david99world Avatar answered Sep 24 '22 04:09

david99world