Skip to content

6. AJ_UnitTest Class

Gary Criblez edited this page Jun 26, 2020 · 3 revisions

Since the 4D version 18 R3, it is possible to use classes inside 4D.

The AJ_UnitTest class is exposed and can be used to replace the New AJ_Tools_UT_describe method.

Parameters

describe : (text) description of the test.

method : (text) method that execute the test (must be "Current method name").

category : (text) (optional) category of the test. This is used to separate multiple tests in different categories.

Return value

return a unit test object with the assert member function. This object will need 4 parameters (given, should, expected, actual) before to call the assert method.

Description

Create a new test. A test can then do multiple assert. Only one test must be created by method.

Exemple

  // __UNIT_TEST

$test:=AJ_UnitTest .new("Sum()";Current method name;"Math")

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

$test.given:="1 parameter (here 5)"
$test.should:="return 10 (addition itself)"
$test.expected:=10
$test.actual:=zz_sum (5)
$test.assert()

$test.given:="3 and 3"
$test.should:="return 6"
$test.expected:=6
$test.actual:=zz_sum (3;3)
$test.assert()

(Available since v2.0.0 of the component)