Database Unit Test Files

Like the unit tests for managed code, database unit tests reside in test projects. You can see the items that compose a database unit test in the hierarchy of a test project in Solution Explorer.

A database unit test consists of multiple items that are contained in several files. The following table describes the files that interact to form a database unit test.

File

Description

.cs or .vb

This source-code file contains a class that is decorated with the [TestClass] attribute. This class contains a single test method for each of the contained database unit tests. These methods are also appropriately decorated with the [TestMethod] attribute.

Each test method contains the appropriate code to exercise the Transact-SQL test script. This code is generated when the test methods are created, and you can modify it.

NoteNote
If you double-click this file in Solution Explorer, the test class opens in the Database Unit Test Designer. To open the .cs or .vb file to see its source code, right-click the file in Solution Explorer, and then click View Code.

.resx

This resource file contains the Transact-SQL scripts defined for your test. This group of scripts includes the pre-test script, the test script, and the post-test script. The resource file contains XML, which you can edit. The resource file is compiled into the test assembly.

You can code your Transact-SQL scripts by using the Database Unit Test Designer. For more information about the scripts that are used in database unit tests, see Scripts in Database Unit Tests.

app.config

This file stores the database connection strings for the test project, in addition to other database unit test configuration settings such as command time-out, data generation file, and so on. For more information, see Overview of Connection Strings and Permissions.

DatabaseSetup.cs or DatabaseSetup.vb

This file contains a class that accesses the connection strings in the app.config file. The class also accesses the information about database schema deployment and the data generation plan that the app.config file of the test project contains. By using a single class, you make it easier for testers to change database providers and connection strings.

See Also

Concepts

Creating and Defining Database Unit Tests

Verifying Database Code by Using Unit Tests

Scripts in Database Unit Tests