Example - Manual - AxUnit - AxUnit - AxUnit,

AxUnit (legacy) CLI Tool (test)

Portfolio
SIMATIC AX
Product
AxUnit
Software version
3.0.4
Edition
08/2025
Language
English (original)
Package Name
@ax/axunit-docs
  • First, the function to be tested has to be ready, for example a function for addition. This may be added in a separate folder, say src.
FUNCTION ADD :INT
    VAR_INPUT
        a:INT;
        b:INT;
    END_VAR

    ADD := a + b;
END_FUNCTION
  • Download and install the AX SDK

  • Next add the tests as separate functions with the preceding pragma {Test}. This may be added in a separate folder, say tests.

{Test}
FUNCTION ADD_of_4_plus_4_returns_8
    VAR_TEMP
        res:INT;
    END_VAR

    res := ADD(a:=4,b:=4);
    AxUnit.Assert.Equal(expected:=8, actual:=res);
END_FUNCTION

{Test}
FUNCTION ADD_of_4_plus_minus4_returns_0
    VAR_TEMP
        res:INT;
    END_VAR

    res := ADD(a:=4,b:=-4);
    AxUnit.Assert.Equal(expected:=0, actual:=res);
END_FUNCTION

{Test}
FUNCTION ADD_of_4_plus_minus4_returns_LessThan_1
    VAR_TEMP
        res:INT;
    END_VAR

    res := ADD(a:=4,b:=-4);
    AxUnit.Assert.LessThan(left:=res, right:=1);
END_Function

this can also be done by using parameterized tests

{Test(i1:=4, i2:= 4, exp:=8)}
{Test(4, -4, 0)}
FUNCTION ADD_returns_correct_result
    VAR_INPUT
        i1  :INT;
        i2  :INT;
        exp :INT;
    END_VAR
    VAR_TEMP
        res :INT;
    END_VAR
    res := ADD(i1, i2);
    AxUnit.Assert.Equal(expected:=exp, actual:=res);
END_FUNCTION

{Test}
FUNCTION ADD_of_4_plus_minus4_returns_LessThan_1
    VAR_TEMP
        res:INT;
    END_VAR

    res := ADD(a:=4,b:=-4);
    AxUnit.Assert.LessThan(left:=res, right:=1);
END_Function