This year’s Professional Developers Conference (PDC) is coming! It’s taking place November 17 – 19th in Los Angeles. If you’re a developer, architect or technology leader involved in making strategic technology decisions, this is the conference you need to attend to stay ahead of the curve and get a head start on planning your company’s product and technology investments.
If you register by September 15, you’ll receive $500 USD off the regular conference pass price.
New to the PDC? Learn more about the big announcements from last year and experience the PDC08 online via Channel 9.
ABOUT PDC
The Professional Developers Conference (PDC) is the definitive developer event focused on the technical strategy of the Microsoft developer platform. Attendees come from around the world to learn about the future of Microsoft developer technology directly from the people who make it happen. If you’re a developer, architect or technology leader involved in making strategic technology decisions for your company or organization, the PDC is for you.
Since 1991, the PDC has been the epicenter of Microsoft’s biggest platform announcements, including Microsoft .NET, Windows® XP, Windows Vista® and Windows 7®. This year, you’ll hear more details about our services platform, Windows®, the Web, devices, and our next generation of developer tools.
WHAT YOU’LL GET AT THE PDC
So that’s it! Will I see you there?
There is some documentation to explain this already, but below is a step-by-step that shows how to use an Excel spreadsheet as a Data Source for both unit and web tests.
First, let’s set the stage. I’m going to use a solution containing a class library and a web site.
The class library has a single class with a single method that simply returns a “hello”-type greeting.
namespace SimpleLibrary { public class Class1 { public string GetGreeting(string name) { return "Hello, " + name; } } }
For my VB friends out there:
Namespace SimpleLibrary Public Class Class1 Public Function GetGreeting(ByVal name As String) As String Return "Hello, " & name End Function End Class End Namespace
Unit Testing
So now I’m going to create a unit test to exercise the “GetGreeting” method. (As always, tests go into a Test project. I’m calling mine “TestStuff”.)
Here’s my straightforward unit test:
[TestMethod()] public void GetGreetingTest() { Class1 target = new Class1(); string name = "Steve"; string expected = "Hello, " + name; string actual; actual = target.GetGreeting(name); Assert.AreEqual(expected, actual);
}
In VB:
<TestMethod()> _ Public Sub GetGreetingTest() Dim target As Class1 = New Class1 Dim name As String = "Steve" Dim expected As String = "Hello, " & name Dim actual As String actual = target.GetGreeting(name) Assert.AreEqual(expected, actual) End Sub
I’ll run it once to make sure it builds, runs, and passes:
I have an Excel file with the following content in Sheet1:
Nothing fancy, but I reserve the right to over-simplify for demo purposes. :)
To create a data-driven unit test that uses this Excel spreadsheet, I basically follow the steps you’d find on MSDN, with the main difference being in how I wire up my data source.
I click on the ellipsis in the Data Connection String property for my unit test.
Follow these steps to set up the Excel spreadsheet as a test data source for a unit test.
[DataSource("System.Data.Odbc", "Dsn=Excel Files;
dbq=|DataDirectory|\\ExcelTestData.xlsx;defaultdir=C:\\TestData;
driverid=1046;maxbuffersize=2048;pagetimeout=5", "Sheet1$",
DataAccessMethod.Sequential),
DeploymentItem("TestStuff\\ExcelTestData.xlsx"), TestMethod()] public void GetGreetingTest() { Class1 target = new Class1(); string name = TestContext.DataRow["FirstName"].ToString(); string expected = "Hello, " + name; string actual; actual = target.GetGreeting(name); Assert.AreEqual(expected, actual); }
Again, in VB: <DataSource("System.Data.Odbc", "Dsn=Excel Files; dbq=|DataDirectory|\ExcelTestData.xlsx;defaultdir=C:\TestData; driverid=1046;maxbuffersize=2048;pagetimeout=5", "Sheet1$", DataAccessMethod.Sequential)> <DeploymentItem("TestStuff\ExcelTestData.xlsx")> <TestMethod()> _ Public Sub GetGreetingTest() Dim target As Class1 = New Class1 Dim name As String = TestContext.DataRow("FirstName").ToString() Dim expected As String = "Hello, " + name Dim actual As String actual = target.GetGreeting(name) Assert.AreEqual(expected, actual) End Sub
Again, in VB:
<DataSource("System.Data.Odbc", "Dsn=Excel Files;
dbq=|DataDirectory|\ExcelTestData.xlsx;defaultdir=C:\TestData;
DataAccessMethod.Sequential)>
<DeploymentItem("TestStuff\ExcelTestData.xlsx")> <TestMethod()> _ Public Sub GetGreetingTest() Dim target As Class1 = New Class1 Dim name As String = TestContext.DataRow("FirstName").ToString() Dim expected As String = "Hello, " + name Dim actual As String actual = target.GetGreeting(name) Assert.AreEqual(expected, actual) End Sub
Yippee!
Web Testing
You can achieve the same thing with a web test. So I’m going to first create a simple web test that records me navigating to the website (at Default.aspx), entering a name in the text box, clicking, submit, and seeing the results. After recording, it looks like this.
See “TxtName=Steve”? The value is what I want to wire up to my Excel spreadsheet. To do that:
That’s it in a simple nutshell! There are other considerations to keep in mind such as concurrent access, additional deployment items, and perhaps using system DSNs, but this should get you started.