Export (0) Print
Expand All

How to: Run Database Unit Tests from Team Foundation Build

You can use Team Foundation Build to run your database unit tests as part of a build verification test (BVT). You can configure your database unit tests to deploy the database, generate test data, and then run selected tests. If you are not familiar with Team Foundation Build, you should review the following information before you follow the procedures in this topic:

Before you use these procedures, you must first configure your working environment by performing the following tasks:

  • Install Team Foundation Build and Team Foundation source control, either as individual products or as part of Visual Studio Team System. You probably need to install Team Foundation Build and Team Foundation source control on different computers.

  • Install Team Explorer on the client computer.

  • Connect a Visual Studio user session to a computer that is running Team Foundation Server. For more information about how to connect to Team Foundation Server, see How to: Connect to Team Foundation Server.

After you configure your working environment, you must then perform the following tasks in Team Edition for Database Professionals:  

  • Create a database project.

  • Import or create the schema and objects for the database project.

  • Configure the database project properties for build and deployment.

  • Create one or more database unit tests.

  • Add the solution that contains the database project and the database unit test project to version control, and check in all files.

The procedures in this topic describe how to create a build type to run your database unit tests as part of an automated test run:

  • Create a test list of database unit tests that you want to run.

  • Check in the test list.

  • Create a build type, specifying that the test list should run as part of the build.

  • Modify the build type to copy the app.config file to the correct location for Team Foundation Build.

  • Check in the updated build type.

  • Run the new build type.

Create a Test List

To create a test list of database unit tests

  1. In the Test Manager window, in the Group By list, click Test List Full Name to display the test list pane.

  2. Right-click Lists of Tests, and then click New Test List.

    The Create New Test List dialog box appears.

  3. Type the name of the test list that will contain your database unit tests. (For example, type Database Unit Tests.)

  4. (Optional) Type a description of your database unit test list, and specify a location in the test list hierarchy to put the new test list.

  5. Click OK.

    Your test list is created and appears in the test list hierarchy pane.

  6. Click All Loaded Tests to display all the tests in your solution.

  7. Drag the tests that you want to run as your database unit tests into the test list that you just created.

    NoteNote

    To drag more than one test at a time, press and hold the CTRL key down as you click each test. To drag a contiguous block of tests, click the first test in the block, and then press and hold the SHIFT key down as you click the last test in the block. Do not use the check boxes for this purpose.

  8. (Optional) To verify the contents of the test list, click it in the test list hierarchy pane.

    The test list that you created, together with all the test lists in your solution, resides in your solution's test metadata file. Test metadata files have the extension .vsmdi. For more information, see Using Test Lists.

Check in the Test List

In this procedure, you check in all the files of your solution. These files include the test metadata file of your solution, which contains your test lists and tests. Whenever you add, delete, reorganize, or change the contents of test lists, your test metadata file is automatically updated to reflect these changes.

NoteNote

This procedure describes the steps if you are using Team Foundation source control. If you are using different version control software, you must follow the steps that are appropriate for your software.

To check in the test list

  1. Connect to a computer that is running Team Foundation Server. For more information, see How to: Connect to Team Foundation Server.

  2. If your solution is not already in source control, add it to source control. For more information, see How to: Add a Project or Solution to Source Control.

  3. Click View, and then click Pending Checkins to display the Pending Checkin window.

  4. Check in all the files of your solution. For more information, see How to: Check In Pending Changes.

    NoteNote

    If you are using Visual Studio Team System, you might have a specific team process that governs how automated tests are created and managed. For example, the process might require that you verify your build locally before you check in that code together with the tests that will be run on it.

    After the check-in operation is finished, a padlock icon appears next to each file in Solution Explorer to indicate that the file is checked in. For more information, see How to: Identify Source Control Item Status in Solution Explorer.

    Your checked-in tests are available to the Team Foundation Build feature of Visual Studio Team System. You can now create a build type that contains the tests that you want to run.

Create a Build Type

To create a build type

  1. In Team Explorer, click your team project.

  2. Right-click Team Builds, and then click New Team Build Type.

    The New Team Build Type Creation Wizard appears.

  3. Follow the steps in the New Team Build Type Creation Wizard. For more information, see How to: Create a New Build Type.

    NoteImportant

    On the Select build options page in the New Team Build Type Creation Wizard, select the Run test check box. Then click the test metadata file that contains the test list that you created in Create a Test List. Finally, select the check box that corresponds to the test list that contains the tests that you want to run.

  4. When you have finished providing information in the wizard, click Finish.

    Your new build type appears in the Team Explorer window under the Team Builds folder.

Modify the Build Type

By default, Team Foundation Build creates an app.config file when it builds the unit tests project. The paths to the data generation plan and database project are stored as relative paths in the app.config file. The relative paths that work from within Visual Studio will not work when Team Foundation Build puts the files in different locations. You can copy the app.config from your test project or you can set up a separate app.config for use with Team Foundation Build. If you copy the app.config from the test project, the modifications in the next procedure will copy the associated files so that Team Foundation Build can find them.

You might create a separate app.config for Team Foundation Build so that you can also use a different database server for your automated tests. The connection string is stored in the app.config file.

To modify the build type to copy the app.config from the test project

  1. In Team Explorer, double-click Source Control to open Source Control Explorer.

  2. Expand your team project, and expand the TeamBuildTypes folder.

  3. Right-click the folder that was created for the build type that you created, and click Get Latest Version.

  4. In the file listings, right-click the TFSBuild.proj file, and click Check Out for Edit.

    The Check Out dialog box appears.

  5. Click Check Out.

  6. On the File menu, point to Open, and click File.

  7. Browse to the TFSBuild.proj file from step 3, and double-click the file to open it in the editor.

  8. Scroll to the bottom of the file, and add the following before the final </Project> element:

    <ItemGroup>
        <ProjectFilesForDeploy Include="BuildPath\TeamProjectName\TeamBuildTypeName\Sources\DatabaseProjectName\*.*"/>
      </ItemGroup>
    
      <Target Name="AfterCompile">
        <Copy
            SourceFiles="@(ProjectFilesForDeploy)"
            DestinationFiles="@(ProjectFilesForDeploy->BuildPath\TeamProjectName\TeamBuildTypeName\DatabaseProjectName\%(RecursiveDir)%(Filename)%(Extension)')"
            />
      </Target>
    
  9. On the File menu, click Save TFSBuild.proj.

To modify the build type to use a different app.config

  1. In Team Explorer, double-click Source Control to open Source Control Explorer.

  2. Expand your team project, and expand the TeamBuildTypes folder.

  3. Right-click the folder that was created for the build type that you created, and click Get Latest Version.

  4. In the file listings, right-click the TFSBuild.proj file, and click Check Out for Edit.

    The Check Out dialog box appears.

  5. Click Check Out.

  6. On the File menu, point to Open, and click File.

  7. Browse to the TFSBuild.proj file from step 3, and double-click the file to open it in the editor.

  8. Scroll to the bottom of the file, and add the following before the final </Project> element:

    <ItemGroup>
        <TestProjectTeamBuildConfigFile Include="BuildPath\TeamProjectName\TeamBuildTypeName\Sources\TestProjectName\TeamBuild.app.config"/>
      </ItemGroup>
    
      <Target Name="AfterCompile">
        <Copy
            SourceFiles="@(TestProjectTeamBuildConfigFile)"
            DestinationFiles="@(TestProjectTeamBuildConfigFile->'BuildPath\TeamProjectName\TeamBuildTypeName\Binaries\Configuration\TestProjectName.dll.config')"
            />
      </Target> 
    
  9. On the File menu, click Save TFSBuild.proj.

Check in the Updated Build Type

To check in the updated build type

  • Repeat the steps that you followed in the procedure To check in the test list to check in the changes to the BuildType.proj file, which contains the build type definition.

Run the New Build Type

To run the new build type

  1. On the Build menu, click Build {TeamProjectName}.

    The Build {TeamProjectName} dialog box appears with a list of all existing build types.

  2. If necessary, in Build type, click your new build type.

  3. (Optional) Change the build location and directory.

  4. Click Build.

    For more information, see How to: Run a Build on a Build Type. To schedule a recurring build, see How to: Configure a Scheduled Build (Command Line).

See Also

Show:
© 2015 Microsoft