Digital Me

Random contributions to digital noise
I prefer simplicity of Excel files for my data-driven unit tests in Visual Studio - both 2005 and 2008. However the new test data source wizard is not supporting Excel files so the connection has to be setup manually.
It is not too hard to set it up, all that is required is addition of DataSourceAttribute to your test method:


[TestMethod]
[DeploymentItem("testData.xls")]
[DataSource(“System.Data.Odbc”,
@”Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=testData.xls;DefaultDir=.”,
“Sheet1$”, DataAccessMethod.Sequential)]

public void SomeTest(){
//some testing
}




DeploymentItemAttribute is there so testData.xls file would be deployed with the test and thus make the test independent of a machine on which it is run. More about using Excel to drive your unit tests with some tips you can find here: Data-Driven Unit Testing using Excel in Visual Studio.

Comments

New comment

required, won't be displayed

optional

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Copyright © 2012 Mihailo Lalevic. All rights reserved.
Powered by Thoth.