Define Custom Conditions for Database Unit Tests

By defining a custom test condition, you can verify the behavior of a database object in ways that the built-in conditions do not support. By default, you can use the following conditions in Visual Studio Team System Database Edition:

  • Empty ResultSet — You can verify that the test returns no results.

  • Execution Time — You can verify that the test takes no longer than the specified period of time to run.

  • Inconclusive — The default condition for all tests always returns a failure result.

  • Not Empty ResultSet — You can verify that the test returns at least one result.

  • Row Count — You can verify that the test returns a specific number of rows.

  • Scalar Value — You can verify that the test returns a specific scalar value.

If you want to test for other conditions, such as verifying the values in a result set, you must create a custom condition. A custom test condition is a type of feature extension. Before you can use a custom condition in the Database Unit Test Designer, you must install the assembly that contains the condition into the global assembly cache. You must then register the condition on any computer on which you intend to use the condition.

Common Tasks

In the following table, you can find descriptions of common tasks that support this scenario and links to more information about how you can successfully complete those tasks.

Common Tasks

Supporting Content

Create a condition: You can create a condition in Visual C# or Visual Basic. You can define multiple conditions in each assembly, but you must register each condition separately.

How to: Create Test Conditions for the Database Unit Test Designer

Walkthrough: Using a Custom Test Condition to Verify the Results of a Stored Procedure

Install and register a condition: Before you can use a custom condition, you must register the condition.

How to: Register and Manage Feature Extensions

Troubleshoot problems: You can learn more about how to troubleshoot common problems with database unit testing.

Troubleshooting Database Unit Testing Issues

Deploy custom conditions: After you verify that your condition works correctly, you must distribute it to your team. Each person who runs a test that uses your condition must register it on the computer on which they run the test. You can ask each team member to install and register the feature extension manually, or you can create a simple installation program for it.

How to: Distribute Custom Feature Extensions to Team Members

  • Generate Test Data for Databases by Using Data Generators
    Before you run database unit tests, you might want to insert representative data into your database. You can use data generators to create realistic data for testing without exposing production data to your developers.

  • Create and Define Database Unit Tests
    You can define unit tests to verify the behavior of your database objects. You can also associate each test project with a different data generation plan, deployment configuration, and connection string.

  • Run Database Unit Tests
    After you have created your database unit tests, you can run them by using several different methods.

See Also


Terminology Overview of Database Edition