How to: Create a Test Case

In Microsoft Dynamics AX, a unit test is code used to test code that implements feature logic. Unit tests include test cases, the set up and tear down of tests, and the organization of one or more test cases. To implement a unit test, you create a test case which is a new class that extends the SysTestCase class.

When you create a test case, you will create a class that must follow the naming convention best practice. Use the same name as the class that you are testing followed by Test. This will associate the test class together with the class you are testing. In this procedure, you will create a class named EmployeeTest that extends the SysTestCase class.

To create a test class

  1. Right-click the Classes node and select New Class.

  2. Double-click Class1 to open the Code Editor.

  3. In the Code Editor, extend SysTestCase by changing the class declaration to the following code.

    class EmployeeTest extends SysTestCase
    {
    }
    

In this procedure you will add a test method. You will do this by adding a method to the EmployeeTest class. You will verify that the name of an employee is set when you use the assertEquals assertion method.

To add a test method for the name requirement

  1. In the AOT, right-click EmployeeTest and then select New Method.

  2. In the Code Editor, change the method to the following code.

    void testName()
    {
       // Verify that the employee name is set correctly.
       this.assertEquals("your name", employee.Name());
    }
    

For a list of the assertion methods, see Unit Test Framework.

Next, you can run a test case and analyze the results. For more information, see How to: Run a Test Case and How to: Display Test Case Results. As your library of test cases grows, you will want to organize test cases into meaningful groups. For information, see How to: Organize Test Cases. It may be necessary to create set up and tear down logic at the test case or suit of test cases level. For more information see, How to: Create Set Up and Tear Down Logic for a Test Case.

Community Additions

ADD
Show: