I was just reading Marc Lehmann post on Code Coverage and I agree with him that a single pass through your code will give you 100% coverage but it doesn't mean you extensively tested the boundaries of your code.
So with this in mind, I'll show you how to setup a link to a database where you can use a table to feed your unit test with all the test cases you need to fully test you code. The unit testing framework of Team System lets you connect to a table and run the same test once for each row in the table.
First you need to connect you unit test to a database table, from the unit test view click on the test you want to connect and look in the property window.
Go to the Data Connection String property and click the … this will show the database connect box
Connect to your test data database this will add the following lines of code to your test (in VB.Net)
<DataSource("System.Data.SqlClient", "Data Source=.;Initial Catalog=TestData;Integrated Security=True", "AddTestData", DataAccessMethod.Sequential)> <TestMethod() > _
Public Sub AddTest()
You now have a connection to the datatable.
Next you need to wire the data coming from that table to your unit test case here's how to do that (I'm showing a unit test method that tests the Add method in my class, obviously the Add method adds two integer and return the value).
Dim target As MyClassLib.MyClassLib = New MyClassLib.MyClassLib
Dim a As Integer = CType(TestContext.DataRow("a"), Integer)
Dim b As Integer = CType(TestContext.DataRow("b"), Integer)
Dim expected As Integer = CType(TestContext.DataRow("res"), Integer)
Dim actual As Integer
actual = target.Add(a, b)
Assert.AreEqual(expected, actual, "MyClassLib.MyClassLib.Add did not return the expected value.")
End Sub
So the most import piece of information here is the TestContext piece. The test harness create a property at the top of the test class here is a copy of it.
Private testContextInstance As TestContext
'''
'''Gets or sets the test context which provides
'''information about and functionality for the current test run.
'''
Public Property TestContext() As TestContext
Get
Return testContextInstance
End Get
Set(ByVal value As TestContext)
testContextInstance = Value
End Set
End Property
This TestContext hold a lot of properties but the one that interests us is the DataRow one, when we are connected to a datatable the DataRow property holds the current row. The test harness will run the test for as many rows as there is in the table. There are two type of data access method we can use, Sequential (all the row in the table in sequential order), and Random (All the row but picked randomly until they are all covered).
When you run the test, the test will pass of fail based on *all* the rows in the table so if one fails the test fails if they all pass then the test pass. Here is a result view of my little test with the following data in "TestData" table
a b res
3 3 6
4 5 9
3 5 8
We should have success and the result is here

So there you have it. Run multiple input through your test so the code coverage will have more meaning.
Happy multipe input testing,
ET