I have a class DBHandler
which takes a query, runs it through the SQL server, checks for errors and returns the result. How can I unit test this class?
Edit: I'll try to be more precise:
DBHandler
is in charge of passing the query to the server. In order to test that it actually does that, throws the correct exceptions, etc., I want to connect it to a mock DB which I will populate. My question is - how to do that? How can I create a mock "server" that handles calls?
Just pass a SQL query, and compare the returned result to expected result. Simple. JUnit is a unit test framework, you can utilise that.
For sophisticated database unit testing, look at DBUnit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With