Table of contents
Official Content

Assertions are the only way to define if a unit test PASSES or FAILS, by comparing the result you get against the expected one.

An assertion is a function that compares the first two parameters and displays a message (3rd parameter) if they are different.

The value obtained is verified through assertions to check if it equals the expected one.

You can use assertions for everything, like a test if database table rows are expected ones or to check if an SDT has the correct (expected) data.

IMPORTANT: You can add as many assertions as you want, but if at least one of them fails, the Test will be marked as FAILED and the error message will be displayed on the Test Results panel. Otherwise, the test will PASS. Currently, there are 4 types of assertions to use inside GXtest Module:

AssertNumericEquals (in:&ExpectedValue, in:&ObtainedValue, in:&ErrorMsgValue)

to verify that 2 numeric values are equal.

AssertStringEquals (in:&ExpectedValue, in:&ObtainedValue, in:&ErrorMsgValue)

to verify that 2 strings are equal.

AssertBoolEquals(in:&ExpectedValue, in:&ObtainedValue, in:&ErrorMsgValue)

to verify that 2 boolean values are equal, or

AssertTrue(in:&Value, in:&ErrorMsgValue)

to directly verify if a value is true.

AssertStringEquals is the most generic and useful function since almost any structure can be serialized as a string.


For example, if you want to test a procedure that uses an SDT as output, you can check its value by comparing the SDT as a JSON string like this:

AssertStringEquals(&SDTcountryExpected.ToJSON(), &SDTcountryObtained.ToJSON(), “The country data is different”)

You might also want to check a specific field of the SDT. You can do this by using something like:

AssertStringEquals(&SDTexpected.fieldX, &SDTobtained.fieldX, “Field X is wrong”)

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant