views:

57

answers:

2

Is there a way to unit-test classes wich require database connections? e.g. User-Classes

(DB-)Object mocking didn't quite help

A: 

Depending on what they do, I suppose you could create a test db and then pass them a test connection string, or perhaps a pre opened connection with appropriately prepared data.

Preet Sangha
+2  A: 

It's generally a good idea to isolate external dependencies, such as databases, from your code, because it makes it easier to test that code. There are some concrete suggestions for dealing with such problems at xunitpatterns.com

troelskn
That is true, but it's still a good idea to unit test the Data Access components as well, and *that* requires a real database.
Mark Seemann
Sure. But you should be able to test this separately from your model layer code.
troelskn