Export (0) Print
Expand All

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 Premium and Visual Studio Ultimate.

  • 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.

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.

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

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

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.

Generating 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.

Creating and Defining 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.

Running Database Unit Tests

After you have created your database unit tests, you can run them by using several different methods.

Community Additions

ADD
Show:
© 2014 Microsoft