Introducing Visual Studio Team System 2008 Database Unit Testing, Page 3
A database unit test can be quite sophisticated. Later in the article, I'll show you how to include data in your test. More advanced testing scenarios, though, are beyond the scope of this article.
Once you complete the configuration information the Database Unit test will look much like the test shown in Figure 7.
Figure 7: Empty Database Unit Test
Like Unit Testing with other types of projects, you write Database Unit Tests in the same language you use for development. In the Database Unit Test, the development language is TSQL.
Most likely, you'll need to operate on some data to execute your tests. So, before I develop the Unit Test, I'm going to create some sample data and later incorporate the data in the Unit Test.
Creating Sample Data
Tests often must be repeated with the same data. Therefore, a Database Unit Test needs a way to repeatedly load the same data. So, first I'll create a Data Generation Plan and then wire the Data to the Database testing project.
Data Generation Plan creation happens inside the Database Development project. Again, select the "Add Items" option on the Database Project. The dialog shown in Figure 8 appears.
Figure 8: Add Data Generation Plan
The initial Data Generation plan appears in Figure 9.
Figure 9: Data Generation Plan
My demonstration focuses on the AWBuildVerion table, so I'm deselecting all but the AWBuildVersion table and the ErrorLog table. Although I'm not initially loading data into the ErrorLog, I'm including it in the plan so that a purge data option I'll select later removes all data from the table before running the test.
Deselected tables are not removed until currently selected tables dependent on the deselected table are in turn deselected. The behavior looks very much like Figure 10.
Figure 10: Deselect tables