Before you can start to write unit tests that evaluate database objects, you must first create a test project. This project contains SQL Server unit tests, but it could contain other types of tests.
You can place all of your SQL Server 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 SQL Server 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 deploy different database projects for different unit tests? | If yes, you need more than one test project. A test project can only deploy a single database project. |
For more information about each of these questions, see How to: Configure SQL Server Unit Test Execution. As an alternative to creating multiple test projects, you can also provide your own DatabaseTestService Microsoft.Data.Schema.UnitTesting.DatabaseTestService implementation.
You have three options for adding a test project to a solution that contains a database project:
Each approach is outlined in the following procedures.