Skip to content

Test cases

  • In the API Maker, you can write test cases of your custom APIs and Utility classes.

Add new test case

Basic info

  • Give the name of the test case.
  • Select the type of test cases from the Custom API | Utility class.
  • If you select the Custom API as the Test cases type, in the next dropdown('Test Item') you have to select the custom API name for which you want to write the test cases.
  • If you select the Utility class as the Test cases type, in the next dropdown('Test Item') you have to select the Utility class name for which you want to write the test cases.

Mock data

  • Add multiple mock methods for the test case.
  • 'Method' is the API Maker's pre-defined API methods.
  • In the 'Function argument' you have to select the data type and its value.
  • 'Mock return value' is the expected value of the test case.

Description

  • Here, we can add more readable text to understand the test case.

Once you save the new test case you will get the default code of the test case like below.

import * as T from 'types';
import * as db from 'db-interfaces';
import * as assert from 'node:assert';

module.exports = [{
    name: 'Test case name 1',
    code: async (g: T.IAMGlobal) => {
        assert.strictEqual(10, 10);
    }
}];

  • As you can see in the above code, we have an array of test case objects.
  • Just write your test case name and define the assertion.

Execute / Run

  • On clicking the 'Execute' button it will run all test cases of the current Test.
  • On clicking the 'Run' button you will see there are checkboxes to select the test cases, and you can run the selected test cases.
  • You will get the proper error details if your test cases are failed.
  • If the test case was run successfully, it has the right(✓) symbol.

Another example of the test cases code.

import * as T from 'types';
import * as db from 'db-interfaces';
import * as assert from 'node:assert';
import * as GetClientSoftwareVersions from 'cloud/getVersion';
import * as ClientSoftware from 'cloud/clientSoftware';
import * as CloudTypes from 'cloud/CloudTypes';

module.exports = [
    {
        name: 'Get client software versions',
        code: async (g: T.IAMGlobal) => {
            const versions = await GetClientSoftwareVersions.getSoftwareVersions(g);
            assert.strictEqual(versions.length > 0, true);
        }
    },
    {
        name: 'Get specific software version',
        code: async (g: T.IAMGlobal) => {
            const version: CloudTypes.IVersion = await ClientSoftware.getSoftwareVersion(g, 'API Maker', 'v1.0.0');
            assert.strictEqual(version.version === 'v1.0.0', true);
        }
    }
];

  • The 'GetClientSoftwareVersions', 'ClientSoftware', and 'CloudTypes' are imported from the utility classes.