How to: Add Test Conditions to Database Unit Tests

This topic applies to:

Visual Studio Ultimate

Visual Studio Premium

Visual Studio 2010 Professional 

Visual Studio Express

Topic applies Topic applies Topic does not apply Topic does not apply

You can add test conditions to a database unit test by using the Database Unit Test Designer. When you save the test class, the test conditions are automatically saved in your test project as C# or Visual Basic code in source-code files. After you save a test condition, you can edit it either in the Database Unit Test Designer or in its source-code file.

To add test conditions to a database unit test

  1. Open a database unit test.

    The name of the test you opened is displayed in the navigation bar at the top of the Database Unit Test Designer. By using navigation bar, you can select the different test methods that are in your test project.

  2. In the navigation bar, click the test method to which you want to add test conditions, or click Common Scripts.

    Note

    Common scripts do not belong to a particular database unit test. Rather, they precede or follow database unit tests in a test run. For more information, see Scripts in Database Unit Tests.

  3. In the navigation bar, click the Transact-SQL script to which you want to add test conditions. You can add test conditions to the pre-test, test, or post-test script.

    The Transact-SQL script for that test appears in the Transact-SQL editor and its test conditions appear in the Test Conditions pane.

  4. In the Test Conditions list, click a test condition and then click Add Test Condition (+).

    The test condition is added to the unit test method.

    Note

    You can reorder test conditions within a test method by clicking a test condition and then clicking the up and down arrows in the Test Conditions pane.

  5. Select the test condition you just added and view the Properties window.

    Configure the test condition in the Properties window. For example, you can change the Execution Time property of an Execution Time test condition. If you set this property, you cause your test to fail if the Transact-SQL script does not execute within the time that you specified.

See Also

Tasks

How to: Create an Empty Database Unit Test

How to: Create Database Unit Tests for Functions, Triggers, and Stored Procedures

How to: Run Database Unit Tests

Concepts

Using Test Conditions in Database Unit Tests

Scripts in Database Unit Tests

Interpreting Database Unit Test Results