
Make a connection between your unit test and your data source
This is the first phase of setting up a unit test to use a data source. In this phase, you make the connection between the unit test method and the data source.
This procedure shows how to use the Properties of the unit test to create the connection. However, you can also create the connection by creating an app.config file and adding connection information to it. The advantage to using an app.config file is that you can change the location of the database without making changes to the unit test itself. For information about how to create and use an app.config file, see Walkthrough: Using a Configuration File to Define a Data Source.
Note: |
|---|
If you are familiar with data connection strings, you can type the data connection string after the first bracket of the [TestMethod()] element instead of using the properties window. |
[DataSource(data connection string goes here), TestMethod()]
To connect your unit test to your data source
Open the solution that contains the test method for which you want to use a data source.
On the Test menu, point to Windows, and then click Test View.
In the Test View window, right-click the unit test for which you want to use a data source and then click Properties.
In the Properties window click Data Connection String and then click the ellipses(…).
Follow the instructions in the in the New Test Data Source Wizard to create the data connection.
A connection string is added to your unit test after the first bracket of the [TestMethod()] element.