Compartir a través de


How to: Run a Test Case

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. Once you create a test case, you will want to run it to analyze the results. Microsoft Dynamics AX provides the following ways to run a test case:

  • From the Unit Test toolbar

  • Programmatically in code at the command prompt

  • From the version control functionality during code check-in

  • From the shortcut menu

For information about how to create a test case, see How to: Create a Test Case. The steps to run a test case are provided in the following procedures.

Running a Test Case from the Unit Test Toolbar

In this procedure, you will access the Unit Test toolbar to run a test case.

To run a test case from the Unit Test toolbar

  1. Click Tools > Unit test > Show toolbar.

    Note

    This displays the Unit Test toolbar.

  2. On the Unit Test toolbar, click the Test drop-down list, and then select the test case that you want to run.

    Note

    If this is the first time that you have used the Unit Test Toolbar there will be no tests in the drop-down list, you must type the name of the test to run.

  3. Click the Parameters button. The following table describes the options in the Unit test parameters form.

    Option

    Description

    Record code coverage

    Mark this check box to record the lines of code that are executed to evaluate your test coverage. For more information, see How to: Access Code Coverage Details.

    Record number of records

    Mark this check box to record the number of records inserted during execution of a test case.

    As you verify data as a measure of quality for your test, use this check box to track inserts to the database. This provides the ability to track cleanup of these records. By tracking all inserts from a unit test and then deleting all the inserted records, the stability of test cases running successively is improved.

    Action on error

    From the drop-down, you can opt to Continue or Fail when an exception occurs.

    Filter

    From the drop-down, you can opt to run Active tests, Check-in tests, or All tests. Use attributes to indicate that a test case is active or a check-in test. You can add more categories to filter on, see How to: Categorize Test Cases Using Attributes.

  4. Close the Unit test parameters form.

  5. On the Unit test toolbar, click Run.

    Note

    When you run the test from the Unit Test toolbar, the Unit Test framework uses the database listener to store the details about the test. For more information about listeners, see How to: Display Test Case Results.

Running a Test Case from the Command Prompt

In this procedure, you will run a test case at the command prompt. There is only one startup command to run tests RunTestProject. This command is used at the project, suite, and test case level. First, the Unit Test framework will search for the name that you specify as a project. If the project is not found, it will search for a test suite with the specified name, and finally it will search for a test case.

To run a test case at the command prompt

  1. On the taskbar, click Start, and then click Run.

  2. Type cmd in the Run box and then click OK.

  3. At the command prompt, type the following: ax32 -StartupCmd=RunTestProject_<name of test>

    Note

    When you use this command, Microsoft Dynamics AX will start and run the test. The Unit Test framework uses the XML listener to store details about the test. The file is saved to the default log directory at C:\Users\<username>\Microsoft\Dynamics Ax\Log\. For more information about listeners, see How to: Display Test Case Results.

Running a Test Case During Version Control Check-in

In this procedure, you will run a test case during the version control code check-in process. You will specify the project that contains a test case to run using the version control functionality during code check-in. If the test fails, code check-in will stop.

To run a test case during version control check-in of code

  1. Click Version Control > System Settings.

  2. In the Version Control Configuration form, in the Best Practice Settings section, set the Test project to the project that you want to run during check-in of code. For more information about version control, see Version Control System.

Running a Test Case from the Shortcut Menu

In this procedure, you will run a test case from the shortcut menu.

To run a test case from the shortcut menu

  • In the AOT, right-click the test case you want to run, point to Add-ins, and then click Run tests.

    Note

    This will open the Unit Test toolbar and initiate the running of the test case.

Next, you can analyze the results of the test case. For more information, see How to: Display Test Case Results. As your library of test cases grows you will want to organize test cases in meaningful groups. For more information, see How to: Organize Test Cases. It may be required to create set up and tear down logic at the test case or suit 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

How to: Create a Test Case

SysTestCase Class

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