A unit test is a way of testing an individual unit of software. A unit is the smallest piece of code that can be logically isolated in a system. The purpose is to validate that each unit of the software performs as designed. In most programming languages, that is a function, a subroutine or a method. In the Software Factory unit tests can be written for the following logic concepts:
- Subroutines (of type Procedure or Scalar Function only)
The image below shows the unit test screen. This is the place to create, maintain and execute unit tests.
The list on the left shows all the objects for which unit tests can be created. Badges are used to show the amount of existing unit tests.
After selecting the correct object and logic type a unit test can be created. A title and description can be filled as well as if the unit test should succeed or not, with the Should abort checkbox. Certain unit tests (e.g., tasks and triggers) may require that the outcome of the unit test must be verified by queries, also known as assertions. When Use assertion query is checked, an assertion query field will appear. This field is filled with an example query by default, showing how the assertion result can be thrown when certain conditions are met.
When a unit test is created, parameters can be added, for which a distinction is made between input, output and row filter. The row filters are used in the where clause when testing update or delete triggers. The output parameters will be checked after the unit test has been executed. In addition, the expected messages can be specified. These will also be checked after performing a unit test. When specific data is needed to meet certain conditions in the code, the best practice will be that the unit test doesn't rely on live data. Instead, data sets can be chosen as mock data, which will guarantee that the necessary data is present for the test.
The Overview tab page shows an overview of all unit tests for the selected project version. By selecting one or multiple rows the unit tests can be executed.
Sometimes a unit test is temporarily unnecessary and shouldn't be executed. Therefore, unit tests can be deactivated and activated again using the Activate unit test and Deactivate unit test tasks.
Unit tests can also be created, maintained or executed from the Functionality modeler.
Unit test in functionality modeler
The list shows all the unit tests that are directly connected with the program objects on the result page. For example, when a default procedure is created for Employee to combine the first and last name to display name, the written unit test that validates the email address is also shown in the list.
Also, all unit tests are shown that have the selected control procedure linked as primarily.
The Analysis menu group provides two cubes to monitor the unit test code coverage.
These cubes rely on the presence of program objects in the model, ensure the definition of the model is fully generated.
Unit test control procedure coverage
The Unit test control procedure coverage cube shows the ratio of control procedures covered by a unit test. Only control procedures of code groups that allow for unit tests are measured.
There are 3 cube views available:
- Coverage per code group
- Coverage per developer
- General coverage
Coverage per code group
The coverage status is determined as following. A control procedure can be either:
- Covered (linked only)
- Not covered
A control procedure counts as covered when a program object item created by the control procedure is present in a program object involved directly in any active unit test.
The covered (linked only) status indicates that the control procedure is linked to an active unit test, but the program object items of this control procedure are not in any program object directly involved in an active unit test.
Not covered means the program object items created by this control procedure are part of program objects not directy involved in any unit test, nor is the control procedure linked to an active unit test.
Unit test program object coverage
The Unit test program object coverage cube is similar to the control procedure coverage cube but measures the number of program objects instead. Only program objects of code groups that can have unit tests are measured.
There are two cube views available:
- Coverage per code group
- General coverage
The coverage for program objects is generally lower than the coverage for control procedures, as a dynamically assigned control procedure might not have a unit test on every program object where it is assigned.