Skip to content

2. Getting started

Gary Criblez edited this page Jun 4, 2020 · 4 revisions

Create a new test method

To create a new test, you must create a new method. You are free to name the method as you want.

Here is how the component will recognize a unit test method : The first line must start with

"// __UNIT_TEST"

After, you can create a new test object by calling the New AJ_Tools_UT_describe method :

   $test:= New AJ_Tools_UT_describe ("AJ_Tools_UT_assert";Current method name;"AJ_Tools_UT Tests")

⚠️ only one "New AJ_Tools_UT_describe" is possible per method !

You can then set the 4 mandatory properties and call the assert member function.

Here this example we test the zz_max method that will return the maximum value passed as parameters :

    // __UNIT_TEST

   $test:= New AJ_Tools_UT_describe ("Test the zz_max_method";Current method name;"Math")

   $test.given:="no arguments"
   $test.should:="return 0"
   $test.expected:=0
   $test.actual:=zz_max
   $test.assert()

   $test.given:="1 and 1"
   $test.should:="return 1"
   $test.expected:=1
   $test.actual:=zz_max (1;1)
   $test.assert()

You can add as many assertions as you need to do your tests.

We recommend you to test one method per test method and to not mix different tests in one big test method.

⚠️ It is important not to forget to check the method attribute "Shared by components and host database" to allow the component to run the method. Else you will get some error message. It often arrives that we forget to set the attribute, so if you see an error message, this is the first thing to check.

Macro

The component come with on macro that will help you to create a new test. You can simply type "_ut_new" and it will create you the minimal structure to make a test.

Main Window

The main window allows you to display and to launch all or partial tests.

There is 2 way of displaying tests : list view and accordion view.

The list view will be filled with the result while the tests are running and when the test is finish, it will display the accordion view.

Here are some screenshots :

1 Listbox View



2 Accordion View - All Tests Passed



3 Accordion View - Some Test Failed