Integration Testing
If you are interested (as judged by your comment) when testing the receipt of data from the database, you will perform the integration test .
The difference in unit testing for these types of tests is that they are performed less frequently - best practice dictates that you run them before committing the source code.
The reason is that they are slower and you will end up in a real database (at least in a test database). On each run, you will need to erase the database or not commit the changes - you seem to know what you are doing here, so I will leave how you deal with it yourself.
Mocking
As for testing your logic, which uses a database - mocking and dependency injection is the way to go.
I use Moq - its probably the easiest mocking structure to use. In fact, this is not only a mock of objects (despite the name), and you can create stubs and fakes with it.
Pseudo mocking goes like this (using the DB example):
- Customize layout
- Tell me what to do (expect) - for example. call to save.
- Use SUT (system test)
- Check the layout - in this case, the save method was called in your SUT.
For more help - check out Google - there are some good unit testing resources and ridicule.
source share