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 DataSource attribute.
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")]
Note |
|---|
| Different providers use different connection strings. The provider itself is a part of connection string. |
For more information about using the app.config file for specifying a data source, see Walkthrough: Using a Configuration File to Define a Data Source.
For more information about data-driven tests, see Overview of Data-Driven Unit Tests.
For more information about using attributes, see Extending Metadata Using Attributes.