The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

daftspaniel (2) [Avatar] Offline
#1
Hi All,

Thanks for the recent update which I have been going through.

I run CI for a web app that is heavily database orientated. I hoping to use NUnit for the next major step up. However the book seems to suggest a) it is not possible or b) create mocks for a database. I am a bit baffled by this given the dominance of databases in business applications.

Databases in CI is probably a chapter or a book in itself smilie

Regards,
Davy Mitchell
craig.berntson (25) [Avatar] Offline
#2
Re: NUnit and Databases
There is nothing stopping you from using unit testing on your web app or your database code. Unit tests should be run as quickly as possible, which often means you can't do database access because it slows down the testing process. Ideally, your tests will complete in less than five minutes.

Another way of looking at this is if you do actually do database access in your unit tests and then the test fails, you need to dig further to determine if it the method being tested or the database code that cause the failure.

Finally, each method under test should be tested in isolation, if at all possible. It shouldn't rely on outside code to do it's job.

All of these problems are resolved with a mock framework. Perhaps you should look at the book "The Art of Unit Testing", also available from Manning.

Now, having said all that, there are still times that you must access your database in unit testing. How do you test the actual database access code without actually accessing the database? Mocks only do so much in this case. We cover this in Chapter 11, "Continuous Database Integration"

Thanks for your comments. We'll look at the chapter on Unit Testing again with your comments in mind.