Chapter 10. Programmer Tests: Using Transactions

In this chapter, we use database transaction support to write programmer tests that are easier to read and are much better at ensuring that the database is left in the correct state when a test is completed. Having to restore the database to its previous state leads to test code such as AddTwoReviewsWithExistingReviewer, which we wrote in the previous chapter. This test has a lot of code that cleans up after itself. In fact, it is hard to see what the test is and what the cleanup code is.

The test code was relatively straightforward in Chapter 5, when we were doing read-only access to the database. However, as we added update capability with the possibility of failure we had to write a lot more cleanup ...

Get Test-Driven Development in Microsoft® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.