Share via


How to: Access Code Coverage Details

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Microsoft Dynamics AX includes a framework to create, run, and analyze test cases. After you create and run a test case, you may be interested in the percentage of code that your tests cover. Various forms exist to display details about test cases. You can also enable one or more listeners. Each listener produces unique output options to display test case results.

For information about creating and running a test case, see How to: Create a Test Case and How to: Run a Test Case.

Displaying Code Coverage Details

You must enable the debugging feature to capture code coverage. In this procedure you will set the debug mode to When Breakpoint. You will also see the various forms available in the Unit Test framework that provide information about the test case after it is run.

To set the debug mode and record code coverage

  1. In a Microsoft Dynamics AX development workspace, click Tools > Options.

  2. On the Options form, click the Development link.

  3. On the Set up options for the development workspace area, in the Debug section, click the Debug mode drop-down list, click When Breakpoint, and then click the Close button.

  4. Click Tools > Unit test > Parameters.

  5. On the Unit test parameters form, click the General link, click the Record code coverage check box and then click the Close button. By default, the Database listener is enabled to capture code coverage.

  6. Click Tools > Unit test > Show toolbar.

  7. On the Unit Test toolbar, click a test to run, and then click Run.

    Note

    When you do not want to capture code coverage, clear the Record code coverage check box. Capturing code coverage causes decreased performance.

The following table describes the Microsoft Dynamics AX forms and details about code coverage.

Form name

How to access

Description

Test jobs (Overview tab)

  1. Click Tools > Unit test > Test jobs.

  2. On the Unit test toolbar, click the Details button.

Displays date, time, author, percent of code coverage, and a pass/fail status for each test.

Test jobs (General link)

On the Test jobs form, click the General tab.

Displays detail specific to an individual test including code coverage, date, time, author, and the duration that the test ran.

Test

On the Test jobs form, click the Tests button.

Displays test case code coverage, status and the duration that the test ran. Also displays the same information at the method level.

Comparison

On the Test form, click the Coverage button.

Displays code coverage details to differentiate between two versions of a class. Click Compare to see the differences.

You can also send the code coverage details to an XML file. The following procedure describes how to access code coverage details in XML format.

To access code coverage details in XML format

  1. Click Tools > Unit test > Parameters.

  2. In the Unit test parameters form, click the Listeners link.

  3. From the Remaining pane, click XML File and click < to add the listener to the Selected pane.

  4. Close the Unit test parameters form.

  5. Click Tools > Unit test > Show toolbar.

  6. On the Unit Test toolbar, click a test to run, and then click Run.

  7. Open the XML file. The default log directory and file name is C:\Users\[User Name]\Microsoft\Dynamics AX\Log\Unit.xml

    Note

    In the XML file, you can see the percentage of code coverage at the test case level and the method level.

Next, think about how to organize your tests in a meaningful way. For information, see How to: Organize Test Cases. It may be necessary to create setup and tear down logic at the test case or suite of test cases level. For more information, see How to: Create Set Up and Tear Down Logic for a Test Case.

See also

Unit Test Framework

Walkthrough: Testing a Class Using the Unit Test Framework

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.