Before starting, make sure you are using a GeneXus version that already supports Unit Testing Framework.
The easiest way to check this is to take a look at your Genexus IDE menu. It should have a “Test” menu on the menu bar:
Unit tests are a new type of Objects in your GeneXus KB with a GeneXus Procedures inside,
The easiest way to create a test is by right-clicking the Procedure you want to test in the KB Navigator and selecting “Create Unit Test” option. This option will ask GeneXus to create a new Unit Test Object that will test the object that you’ve selected.
For this purpose, a new unit test will be automatically generated, where you will need to add input and output to your test. By default, the test includes an arrange section where the parameters of the procedure which are set as "in" are initialized. Moreover, the ones that are set as "out" are created as assertions on the assert section.
For example, let's imagine a very simple test that verifies the result of a procedure called "Sum1". That procedure only adds 1 to a number, so this could be a very simple test:
Please note that autogenerated code (template) is intended to be fully edited to add different inputs and validating output using assertions.
Assertions are used to validate the procedure's result/output during test execution, usually by comparing some output variable with an expected value. Any number of assertions can be added to a Test, each validating some different results. If any of them fail, Test result will be FAILED.
You can add some assertions navigating results using FOREACH as usual, comparing database results from your procedures, compare expected SDTs, calls to services, Data Providers and Business Components.