Creating Unit Tests

Official Content

Before starting, make sure you are using a GeneXus version that already supports the 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:
image_201831418284_1_png

If you don't have this option, check here how to install it.

Unit tests are a new type of Object in your GeneXus KB with the particularity of being a special GeneXus Procedure. This means that you can write GeneXus code inside it for testing your objects with different data and validations (assertions). The easiest way to create a unit test is by right-clicking the Procedure you want to test in the KB Navigator and selecting the “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 probably need to add different data input and output to test different scenarios.

By default, the test generates 3 objects: 

  • an SDT for handle input and output structure
  • a DataProvider containing the test data that will be used
  • a UnitTest object with the code of the test that you need to modify.

Here you can find a video explaining these 3 objects: https://training.genexus.com/gxtest-es/overview-gxtest-4-0?es#explaining-unit-test-objects

For example, let's imagine a very simple procedure that concatenates two input strings received by parameter, called "stringConcatenation". So this will be a simple test auto-generated:
image_2019415101519_1_png

Note this auto-generated code iterates over a collection of data (StringConcatenationUnitTestData), an auto-generated data provider that you will need to edit for your different test scenarios:

 

image_2019415101923_1_png

So, this data provider enables you to run the test with several data combinations. Please note that the 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 an 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, the Test result will be FAILED.

You can also add database assertions navigating results using FOREACH as usual, comparing database results against your procedure's output.

Lastly, you can also test other types of programmatic objects (with no UI), like Data Providers and Business Components.

 
 
Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.