Unit testing a database connection and general questions on database-dependent code and unit testing

Posted by dotnetdev on Stack Overflow See other posts from Stack Overflow or by dotnetdev
Published on 2011-01-08T00:42:46Z Indexed on 2011/01/08 0:53 UTC
Read the original article Hit count: 776

Filed under:
|
|

Hi,

If I have a method which establishes a database connection, how could this method be tested? Returning a bool in the event of a successful connection is one way, but is that the best way?

From a testability method, is it best to have the connection method as one method and the method to get data back a seperate method?

Also, how would I test methods which get back data from a database? I may do an assert against expected data but the actual data can change and still be the right resultset.

EDIT: For the last point, to check data, if it's supposed to be a list of cars, then I can check they are real car models. Or if they are a bunch of web servers, I can have a list of existant web servers on the system, return that from the code under test, and get the test result. If the results are different, the data is the issue but the query not?

THnaks

© Stack Overflow or respective owner

Related posts about java

Related posts about unit-testing