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?
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.