Loading

DataSourceAttribute Class

You can use the DataSource attribute to call your TestMethod multiple times with different data each time.

The DataSourceAttribute class provides two ways to specify data source information for data-driven tests. The first way specifies information through a connection string, provider information, and source table name passed to the DataSourceAttribute.

Connection String Example:

[DataSource("Provider=SQLOLEDB.1;Data Source=MySource;Integrated] Security=SSPI;Initial Catalog=MyCatalog;Persist Security Info=False", "MyTable")]

The second way passes a single argument to the attribute that specifies the configuration setting located in the app.config file.

Configuration Setting Example:

[DataSource("dataSourceNameFromConfigFile")]

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.datasourceattribute.aspx

demo:

https://files.cnblogs.com/joe-yang/Data-Driven_Unit_Test.zip

posted @ 2011-06-15 22:22  .net's  阅读(457)  评论(0)    收藏  举报