The decision whether a test fails or not is done and communicated to the test
environment by the Assert functions. There are different kind of assert functions for different data types.
The Assert functions are in the AxUnit namespace.
| Provided Assertions | Parameter | Supported Type |
|---|---|---|
Equal |
expected, actual | BOOL, INT, SINT, DINT, LINT, USINT, UINT, UDINT, ULINT, REAL, LREAL |
NotEqual |
expected, actual | BOOL, INT, SINT, DINT, LINT, USINT, UINT, UDINT, ULINT, REAL, LREAL |
LessThan |
left, right | INT, SINT, DINT, LINT, USINT, UINT, UDINT, ULINT, REAL, LREAL |
GreaterThan |
left, right | INT, SINT, DINT, LINT, USINT, UINT, UDINT, ULINT, REAL, LREAL |
{Test(value1 := 1, value2:= 2, exp := 3)}
FUNCTION Adding_Two_Numbers_Returns_The_Sum
VAR_INPUT
value1 :INT;
value2 :INT;
exp :INT;
END_VAR
VAR_TEMP
result :INT;
END_VAR
result := ADD(value1, value2);
AxUnit.Assert.Equal(exp, result);
END_FUNCTION
Warning
Currently we are only supporting a limited amount of failed assert statements for each test. If you run into the problem that not all asserts are covered in the test execution there are several solutions:
- Correct or change your code so that the failed asserts are passing.
- Write more tests in order to spread out the asserts, ideally one per test!
- Use pragmas to test your asserts with different input values.