Dela via


How to: Identify the Test Impact of Code Changes During Development

By using Test Impact Analysis, you can help ensure the quality of your code in two ways. First, you can determine which tests you should run to verify one or more code changes that you have already made. Second, you can determine which tests you would have to run if you changed a particular method, even if you have not yet made a specific change.

Note

Test Impact Analysis is not supported on obfuscated binaries.

Before you can use Test Impact Analysis, you must first initialize test impact data collection, and then create a baseline of data for analysis. After you have enabled test impact analysis, build your solution and then run the tests in the test projects.

When you make code changes and rebuild your solution, test and methods that have been affected by code changes appear in Test Impact View.

To initialize test impact data collection and generate baseline data

  • Open the solution that contains the code projects and the unit test projects for which you want to collect data.

Note

Test impact analysis requires that the solution that contains the code projects and the unit test projects for which you want to collect data is opened in the Visual Studio IDE.

  1. In Solution Explorer, double-click the local.testsettings file.

    The Configuration Settings - local.testsettings dialog box appears.

  2. In the navigation bar, click Data and Diagnostics.

  3. In the Role list, make sure that <Local machine only> is selected.

  4. In the Data and Diagnostics for selected role list, select the Test Impact check box.

  5. Do the following steps if you are collecting data for an ASP.NET Web application:

    1. If the machine is acting as a client to the Web application that is running either locally or remotely, select the ASP.NET Client Proxy for IntelliTrace and Test Impact check box. This setting determines whether Internet Information Services is instrumented for data collection.

    2. If the machine is also acting as the server for the Web application, select Test Impact and then click Configure, located above the list of data diagnostic adapters. Click the Advanced tab and make sure that Collect data from ASP.NET applications running on Internet Information Services is selected.

  6. Click Apply, and then click Close.

  7. Rebuild your solution.

  8. Run the tests in your test projects.

    Test Impact Analysis is now initialized.

To list tests that you must run to verify pending changes

  1. After you have made changes to the code, rebuild your solution.

  2. On the Test menu, click Windows, and then click Test Impact View.

    Test Impact View appears.

  3. Click Show Impacted Tests.

    Test Impact View lists tests that you must run to verify the code changes. If no tests exist that verify the code changes, No tests are impacted appears.

  4. (Optional) Highlight one or more of the tests, and on the Test Impact View toolbar, click Run Selection.

To view all code changes

  1. On the Test menu, click Windows, and then click Test Impact View.

    Test Impact View appears.

  2. On the Test Impact View toolbar, click Show Code Changes.

    All changed methods appear at the top of the Test Impact View. You can highlight one or more changes to list the tests that apply to each change in the Impacted Tests list below.

  3. (Optional) Highlight one or more of the tests, and on the Test Impact View toolbar, click Run Impacted Tests.

To list or run tests that call a specific method

  1. In the code window, right-click anywhere in the method.

  2. Do one of the following:

    • To list the tests that call the method, click Show Calling Tests. The names of the tests appear in Test Impact View.

    • To run all the tests that call the method, click Run Calling Tests. The tests are run and the results appear in the Test Results window.

To remove affected test or changed code methods from Test Impact View

  • In Test Impact View, right-click one or more test or code methods and then click Ignore Selection.

    The selected test methods are removed from the Impacted test list and not run. Selected code methods are removed from the Code changes list and test methods affected by the code change are removed from the Impacted test list and not run.

See Also

Concepts

Identifying Code Change Impact on Tests