The K Test Core library provides a framework for configuring and running automated unit and integrations tests. It will run tests on client and server actions.
Use the K Test Manager forge component to provide a user interface for the to the manage test cases.
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 Server 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.
Note: Consider using the Server Action Tests screen template to create the boilerplate code for your test cases. It will create the server actions for the test; then just delete the screen.
To write a server test case
Create an server action naming it with the target and scenario.
For example, testing an action ProcessStructure with large data values call the test Test_ProcessStructure_WithLargeData
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
Client Side Tests - Installation
The "K Test Client Actions Core" library contains all the client actions required to write unit tests for client actions. It depends on K Test Core.
Client unit tests are run on the server using Puppeteer. You can also run client tests manually by opening the page yourself.
To add the library:
Now write each set of unit tests as a test script.
How to Write a Client Test Script
The test script runs all the test cases for the script (see below for writing a test case).
Consider using the Client Action Tests screen template to create the boilerplate code for your test cases. It will create the screen and client actions for the test.
To write a test script
Write as many test cases as you need. This is your test script.
Add the TestResultsBlock to your page to display the test results immediately. Otherwise view results of tests in the K Test Manager.
How to Write a Client Test Case
The test case verifies a particular "target", normally a client action, for a particular scenario.
To write a test case
Have a look at the demo app KTestClientActionsDemo to see an example of client unit tests. Notice it has a pattern for creating a unit test template for testing a particular client action. This pattern helps writing unit tests quickly for differing scenarios.
The K Test Core library provides a framework for configuring and running automated unit and integrations tests.
How to Write a Test Case
Create an action naming it with the target and scenario.