20.4. Testing Context
When you are writing test cases, the testing engine can assist you in a number of ways, including by managing sets of data so you can run a test case with a range of data, and by enabling you to output additional information for the test case to aid in debugging. This functionality is available through the TestContext object that is generated within a test class.
20.4.1. Data
The CurrentStatusTest method generated in the first section of this chapter tested only a single path through the CurrentStatus property. To fully test this method, you could have written additional statements and assertions to set up and test the Subscription object. However, this process is fairly repetitive and would need to be updated if you ever changed the structure of the CurrentStatus property. An alternative is to provide a DataSource for the CurrentStatusTest method whereby each row of data tests a different path through the property. To add appropriate data to this method, use the following process:
Create a local database and database table to store the various test data. In this case, create a database called LoadTest with a table called Subscription_CurrentStatus. The table has an Identity column called Id, a nullable DateTime column called PaidUp, and an nvarchar(20) column called Status.
Add appropriate data values to the table to cover all paths through the code. Test values for the CurrentStatus property are shown in Figure 20-6.
Figure 20.6. Figure 20-6
Select the ...
Get Professional Visual Studio® 2008 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.