How to unit test an SQL query?
I'd use dependency injection to pass in the database connection or something similar, so that the whole thing can be mocked out in the tests. Then you can write tests where the mock query throws exceptions, returns various errors or valid results. Then your tests are just checking that DBHandler
performs correctly.
You'll want to either use an in-memory test database that you create and populate on set-up or make all your tests transactional so they don't alter your test database.
You'll have to worry about the presence of data.
If you're using Spring, they have support for transactional unit tests.
It's not clear what you're asking. You already know about JUnit. What do you think you're missing?