Unofficial Content

If we have a function that validates a login - the procedure receives the login and password and returns a set of messages and a result {ok, fail, exception} 

LoginValidate(in:&UserLogin, in:&UserPassword, out:&ApiMessages, out:&ApiResult)

To test this procedure we can think of several test-cases - for example if i call it with a valid &UserLogin and password it should return an OK result... if i call with an invalid UserLogin it should return fail, and so on), we start by creating a Suite that will group all our tests

i2017_03_29_12_40_405_png

And within the Suite we can create the tests

i2017_03_29_12_41_116_png

This will open up the Object creation dialog and the only thing it does is to create a procedure under the folder GxUnit\GxUnitSuites\<YourSuite>\<YourTest>. You can get the same results by creating the procedure in there and then hit Refresh in the GxUnit tool-window

i2017_03_29_12_43_017_png

i2017_03_24_20_49_528_png

In the example the names of the test follows a convention - "Test" + the name of the procedure we are testing + the test case/values + expected result - you can choose your own. Consider that when you see the results of the test execution you will see the name of the test and the results of the asserted values, so the name is important.

Procedure: TestLoginValidate_InvalidBlankUser_ReturnExcep

&UserLogin = ''
&UserPassword = ''
LoginValidate(&UserLogin, &UserPassword, &ApiMessages, &ApiResult)

GXUnit_AssertStringEquals('ApiResult', &ApiResult.ToString(), 'EX')

The code above is the content of one test... as mentioned you call the procedure/unit you want to test (i.e. validate login) and asser that under the call-conditions (i.e. a blank login and blank password) we obtain the expected value (i.e. EXCEPTION .. ).  When this program is executed if we obtain 'EX' the test will be a pass while if we obtain something different than 'EX' it will be a fail.

Once your tests are written you are ready to execute them. See GxUnit_RunTests

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant