K Test Core

K Test Core (ODC)

Stable version 1.0.6 (Compatible with ODC)
Uploaded on 25 October 2024 by Kiandra IT
K Test Core

K Test Core (ODC)

Documentation
1.0.6


The K Test Core library provides a framework for configuring and running automated unit and integrations tests.

Use this library to help build your unit tests. Use the assertion actions to check expected values of test results.

Use the K Test Manager forge component to the schedule, run and manage test scripts.

The forge components are separated as your code will depend on this component, whereas the K Test Manager only needs to be deployed to the dev environment.

How to Write a Test Case

A test case verifies the result for a scenario of use, or "case", of a target operation.

Decide on the action or component, known as the target, to be tested. Then decide on the scenarios to test. Scenarios could include single value, multiple values, zero values, expected exceptions. It helps to Consider the "contract" of the target to determine scenarios.

To write a test case

  1. Create an action naming it with the target and scenario.

    For example, testing an action ProcessStructure with large data values call the test Test_ProcessStructure_WithLargeData

  2. Add a parameter called ScriptRunId of type TestScriptRun Identifier. Pass the ScriptRunId from the REST API method to the action.
  3. Call TestCaseRun_Start to start the test case. It takes a TestScriptRun Identifier parameter and will associate results with the active script run.
  4. Set the Name as the name of the scenario. eg "With Large Data"
  5. Set the Target as the action or component being tested.
    eg ProcessStructure
  6. Store the TestCaseRunId returned from the TestCaseRun_Start action in a local variable
  7. Add an exception handler for AllExceptions which should call the Assert_ExceptionThrown action. This ensures an failure is recorded if an exception is thrown.
  8. Set up the data to be tested. This is the "Arrange" step.
  9. Call the action to test. This is the "Act" step.
  10. Use Assertion service actions from the K Test_Core module to check the results of the action. Create as many assertions as you need. This is the "Assert" step.
  11. Call TestCaseRun_End to complete the test case. If any assertions have failed, the test case will be set to failed.

Write as many test cases and call them from the REST API. This is your test script.

Expose a REST API to Run the Script

Expose a REST API for the Test Manager to call when the script runs.

To expose a REST API for the script

  1. In the module where you will write tests, navigate to Logic > Integrations > REST.
  2. Right-click on REST and select Expose REST API. Give it a name, eg UnitTests
  3. Under Security, set Internal Access Only to Yes.
  4. Set the Authentication property. Note this should match the Authentication Scheme set when you configure a script to call the REST API.
    1. For None, there is nothing more to do.
    2. For Basic, you will need to specify the username and password when you configure the script.
    3. For Custom, implement the OnAuthentication method. Call GetRequestHeader (From the HttpRequestHandler module) to get the "Authorization" header. Then call TestScriptRun_AuthenticateBearerToken() passing the value of the Authorization header.
  5. Right-click on the API and select Add REST API Method. Name the method, eg RunTests
  6. Set the HTTP Method to POST (otherwise you will get a MethodNotAllowed error).
  7. Add a parameter to the method named Request. Ensure Receive In is set to Body. Set its Data Type to structure TestScriptRequest from KTest_CS. Notice the structure has a single parameter ScriptRunId of type TestScriptRun identifier. This parameter is required to record test cases for the script run.
  8. In the method call a server action to run the unit tests.