Question

I am trying to do some TDD with the unit of work / repository pattern not in MVC. The problem MSDN and other sources say that I need to create inMemoryRepositories to represent my repositories in the test project.

Using this test repositories I add and remove items from a list and check if the output is what I expect when I use the repositories from the controller (client code in my case).

The problem is that right now I have not developed any client code that uses the repositories rather I have implemented the repositories themselves as a library that will be supplied to other applications as a service between them and the database.

What I need to know is that they work correctly with inserting or searching to and from the database. This is not something I find in any tutorials or guides and I am not sure what is the optimal way to perform this testing.

Any pointers will be much appreciated.

Was it helpful?

Solution

What you require - testing actual data changes - is not unit-testing and that's why you're not seeing it done in the tutorials. Unit testing tests business logic.

Here's a quote from the TDD Wikipedia entry:

The tests used for TDD should never cross process boundaries in a program, let alone network connections. Doing so introduces delays that make tests run slowly and discourage developers from running the whole suite. Introducing dependencies on external modules or data also turns unit tests into integration tests.

This is very good advise in my experience.

If you really want to test data changes you can set up another test project for integration tests. Keep the unit-testing clean and pure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top