Export (0) Print
Expand All

DataSourceAttribute Class

Provides data source-specific information for data-driven testing. This class cannot be inherited.

Namespace: Microsoft.VisualStudio.TestTools.UnitTesting
Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework (in microsoft.visualstudio.qualitytools.unittestframework.dll)

[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple=false)] 
public ref class DataSourceAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple=false) */ 
public final class DataSourceAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple=false) 
public final class DataSourceAttribute extends Attribute

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")]

NoteNote

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.

The following code contains the class and method to test.

No code example is currently available or this language may not be supported.

The following test will pass. It uses the sample.mdb access database that contains the following data in Table1.

Name

Balance

Amount

Jorg Bott

100

25

Pedro Ruivo

70

60

Mandar Samant

75

71.25

Russell King

159

158

Jun Cao

11.99

11.22

Note that the DataAccessMethod is sequential.

No code example is currently available or this language may not be supported.

System.Object
   System.Attribute
    Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft