Dela via


How to: Configure Code Coverage Using Test Settings for Automated Tests

You can configure the diagnostic data adapter that collects code coverage data from Microsoft Visual Studio 2010. You can use the code coverage diagnostic data adapter to identify what proportion of your project's code is being tested when the test is run.

If you want to collect code coverage data when you run tests, Visual Studio must first instrument assemblies for the application under test. The instrumentation process adds code to the assembly so that code coverage data can be generated.

Note

You can only use code coverage when you run an automated test, and only from the computer that is running the test. Remote collection is not supported. You cannot use code coverage when you run tests from a test plan using Microsoft Test Manager.

For more information, see Using Code Coverage to Determine How Much Code Is Being Tested.

Warning

Collecting code coverage data does not work if you also have the test setting configured to collect IntelliTrace information.

The following procedure describes how to configure code coverage from the configuration editor for your test settings. These steps apply to Microsoft Visual Studio 2010.

Configure Code Coverage for your Test Settings for Automated Tests

Before you perform the steps in this procedure, you must open your test settings from Microsoft Visual Studio 2010, and then select the Data and Diagnostics page.

To configure code coverage for your test settings for automated tests

  1. Select the role to use to collect code coverage data.

    Warning

    For code coverage data this must be the role that will run the tests.

  2. To modify the default code coverage settings, select the check box for Code Coverage and then click Configure located immediately above the list of diagnostic data adapters.

    The Code Coverage Detail dialog box to configure code coverage collection is displayed.

    Warning

    Collecting code coverage data does not work if you also have the test setting configured to collect IntelliTrace information.

  3. From the list, select the artifacts that you want to instrument.

  4. (Optional) To add another assembly that is not displayed, click Add Assembly.

    The Choose Assemblies to Instrument dialog box is displayed.

    1. Locate the assembly file (.exe, .dll, or .ocx) that you want to include in code coverage and then click Open. The file is added to the list.
  5. (Optional) Select Instrument assemblies in place to instrument the files in the location where they are built or after you copy them to a deployment directory. For more information about where to instrument your assemblies, see Choosing the Instrumentation Folder.

  6. (Optional) If any one of your assemblies that you added have a strong name, you might have to re-sign these assemblies. Click () to locate the key file that must be used when they are re-signed. For more information about how assemblies are re-signed, see Instrumenting and Re-Signing Assemblies.

  7. Click OK. The code coverage settings are now configured and saved for your test settings.

    Note

    To reset the configuration for this diagnostic data adapter, click Reset to default configuration.

See Also

Tasks

Create Test Settings to Run Automated Tests from Visual Studio

Concepts

Setting Up Machines and Collecting Diagnostic Information Using Test Settings

Running Automated Tests