Unit Tests


With the core functionality, providers, factories, runtime configuration classes, and design-time capabilities in place, the application block is now able to be used by developers and administrators in the same way that all the other application blocks that ship with Enterprise Library can be. There are, however, some additional best practices that the Microsoft patterns & practices team recommends when building and deploying an application block.

At the top of this list is the creation and use of unit tests. This is important for several reasons. First, it validates that the block works the way it is supposed to work. Second, it provides a method for ensuring that the same functionality can be provided as new providers need to be created for a particular block; the tests can help to ensure that the new provider can supply the required functionality while adhering to the interfaces contained in a particular block. Enterprise Library was developed using Test-Driven Development (TDD) methods. The unit tests are seen as extremely important to verify the functionality of application blocks and to verify that modifications to application blocks have not caused regression during the development of the blocks. The unit tests also have the additional benefit of providing sample code to developers on how certain functions should behave in the application block.

For example, the Data Mapping Application Block includes unit tests for testing virtually all aspects of the application block. These tests were extremely valuable during the development of the application block because as changes needed to be worked into the code (and changes always do), the unit tests could be run to ensure that these changes did not adversely affect the behavior of the application block. Listing 9.14 shows a couple of the unit tests that exist for the DatabaseWrapper class.

Listing 9.14. DatabaseWrapper Unit Tests

[C#] [Test] [ExpectedException(typeof(DataWrapperException))] public void InvalidSelectCommandThrowsException() {     IDataReader dataReader =          DatabaseWrapper.GetDataReader(typeof(CustomersDS),          SR.TestCustomersForException);     dataReader.Close();     Assert.IsNotNull(dataReader); } [Test] public void GetNamedDataReaderWithNoParameters() {     IDataReader dataReader =               DatabaseWrapper.GetDataReader(typeof(CustomersDS),               SR.TestCustomers);     dataReader.Close();     Assert.IsNotNull(dataReader); } [Visual Basic] <Test, ExpectedException(GetType(DataWrapperException))> _ Public Sub InvalidSelectCommandThrowsException()     Dim dataReader As IDataReader = _          DatabaseWrapper.GetDataReader(GetType(CustomersDS), _          SR.TestCustomersForException)     dataReader.Close()     Assert.IsNotNull(dataReader) End Sub <Test> _ Public Sub GetNamedDataReaderWithNoParameters()     Dim dataReader As IDataReader = _          DatabaseWrapper.GetDataReader(GetType(CustomersDS), _          SR.TestCustomers)     dataReader.Close()     Assert.IsNotNull(dataReader) End Sub




Fenster Effective Use of Microsoft Enterprise Library(c) Building Blocks for Creating Enterprise Applications and Services 2006
Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications and Services
ISBN: 0321334213
EAN: 2147483647
Year: 2004
Pages: 103
Authors: Len Fenster

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