Share via


How to: Create a Test Project for Database Unit Testing

Before you can start to write unit tests that evaluate database objects, you must first create a test project. This project is available in Visual Studio Premium or Visual Studio Ultimate. This project contains database unit tests, but it could contain other types of tests, too.

You can place all of your database unit tests for a given database project within a single test project. However, you might want to create additional test projects based on your answers to the following questions:

Question

Decision

Do different database unit tests need to access different database connections for test execution or test validation?

If yes, you need more than one test project. You cannot specify more than one database connection for test execution. However, you can specify a different database connection for test validation.

Do you want to specify a different deployment configuration for different unit tests?

If yes, you need more than one test project. You cannot specify multiple deployment configurations for the same test project.

Do you want different unit tests to use different data generation plans?

If yes, you need more than one test project. You cannot specify multiple data generation plans for the same test project.

For more information about each of these questions, see How to: Configure Database Unit Test Execution. As an alternative to creating multiple test projects, you can also provide your own DatabaseTestService implementation.

You have two options for adding a test project to a solution that contains a database project:

  • Add a test project to the solution. The test project contains a standard unit test, which you can delete. This project does not contain a database unit test class, which you must add.

  • Create a database unit test from the Test menu. When you create the unit test, Visual Studio Premium also creates a test project if you request it. This project contains a database unit test class. Database test classes contain one or more unit tests.

Each approach is outlined in the following procedures.

To add a test project to an existing solution

  1. Open the solution that contains the database project that you want to test.

  2. On the File menu, point to Add, and click New Project.

    The New Project dialog box appears.

  3. In Installed Templates, expand the Visual Basic or Visual C# node, and click Test.

  4. In the details pane, click Test Project if it is not already highlighted.

  5. On the Test menu, point to Test Windows, and click Test View.

  6. Type the appropriate Name and Location, and then click OK.

    A test project is added to the existing solution. This project contains a unit test for managed code, which you cannot view in the Database Unit Test Designer. Delete this test from Test View, and add a database unit test. For more information about how to add a database unit test, see How to: Create an Empty Database Unit Test.

To create a test project with a database unit test class