Chapter 10: Programmer Tests: Using Transactions


Overview

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, Programmer Tests: Using TDD with ADO.NET, 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 code. It is time to address this problem with a different technique. As we mentioned in Chapter 5, it is possible to use the transactional rollback functionality in the database to automatically remove the data created by the programmer tests. This seems like a cleaner approach in light of the update requirements.

Note  

If you are not familiar with transactions in ADO.NET, see Appendix B, Transactions in ADO.NET, for a brief overview or see Pragmatic ADO.NET by Shawn Wildermuth.




Test-Driven Development in Microsoft .NET
Test-Driven Development in Microsoft .NET (Microsoft Professional)
ISBN: 0735619484
EAN: 2147483647
Year: 2004
Pages: 85

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net