Skip to content

Commit c7c8563

Browse files
committed
feat(xUnitXmlPublisher): Include assertion message in test output
1 parent 3967918 commit c7c8563

9 files changed

+396
-136
lines changed

TcUnit/TcUnit/DUTs/ST_TestCaseResult.TcDUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ STRUCT
88
TestIsFailed : BOOL;
99
TestIsSkipped : BOOL;
1010
FailureMessage : T_MaxString;
11+
FailureAssertion : Tc2_System.T_MaxString;
1112
FailureType : E_AssertionType;
1213
NumberOfAsserts : UINT;
1314
Duration : LREAL; // in seconds

TcUnit/TcUnit/ITFs/I_AssertMessageFormatter.TcIO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Declaration><![CDATA[INTERFACE I_AssertMessageFormatter
55
]]></Declaration>
66
<Method Name="LogAssertFailure" Id="{35efab01-6ac8-46a5-a5e1-adb4f1f5f9b2}">
7-
<Declaration><![CDATA[METHOD LogAssertFailure
7+
<Declaration><![CDATA[METHOD LogAssertFailure : Tc2_System.T_MaxString
88
VAR_INPUT
99
Expected : T_MaxString;
1010
Actual : T_MaxString;

TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FUNCTION_BLOCK FB_AdsAssertMessageFormatter IMPLEMENTS I_AssertMessageFormatter]
1111
<ST><![CDATA[]]></ST>
1212
</Implementation>
1313
<Method Name="LogAssertFailure" Id="{48cbc6b0-5380-44b8-a045-57b6ad9f189d}">
14-
<Declaration><![CDATA[METHOD PUBLIC LogAssertFailure
14+
<Declaration><![CDATA[METHOD PUBLIC LogAssertFailure : Tc2_System.T_MaxString
1515
VAR_INPUT
1616
Expected : T_MaxString;
1717
Actual : T_MaxString;
@@ -24,7 +24,7 @@ VAR
2424
TestInstancePathFinal : T_MaxString;
2525
ReturnValue : DINT;
2626
TestInstancePathProcessed : T_MaxString;
27-
MessageProcessed : T_MaxString;
27+
MessageProcessed : Tc2_System.T_MaxString;
2828
END_VAR]]></Declaration>
2929
<Implementation>
3030
<ST><![CDATA[TestInstancePathCleaned := F_RemoveInstancePathAndProjectNameFromTestInstancePath(TestInstancePath);
@@ -34,10 +34,13 @@ TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := '$'');
3434
IF LEN(STR := Expected) > 0 THEN
3535
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', EXP: ');
3636
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := Expected);
37+
LogAssertFailure := Tc2_Standard.CONCAT('EXP: ', Expected);
3738
END_IF
3839
IF LEN(STR := Actual) > 0 THEN
3940
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', ACT: ');
4041
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := Actual);
42+
LogAssertFailure := Tc2_Standard.CONCAT(LogAssertFailure, ', ACT: ');
43+
LogAssertFailure := Tc2_Standard.CONCAT(LogAssertFailure, Actual);
4144
END_IF
4245
IF LEN(STR := Message) > 0 THEN
4346
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', MSG: %s');

TcUnit/TcUnit/POUs/FB_Test.TcPOU

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ VAR
1919
(* Failure parameters. If TestIsFailed is TRUE, the other parameters will hold values as well *)
2020
TestIsFailed : BOOL; // Indication of whether this test has at least one failed assert
2121
AssertionMessage : T_MaxString; // Assertion message for the first assertion in this test
22+
AssertionFailure : Tc2_System.T_MaxString; // Assertion failure for the first assertion in this test
2223
AssertionType : E_AssertionType; // Assertion type for the first assertion in this test
2324
2425
StartedAt : LWORD; // Temporary variable to calculate the actual duration of the test, the value holds the cpu cycle counter when a test is started in 100ns precision
@@ -27,6 +28,12 @@ END_VAR]]></Declaration>
2728
<Implementation>
2829
<ST><![CDATA[]]></ST>
2930
</Implementation>
31+
<Method Name="GetAssertionFailure" Id="{fca1dda8-8d75-01ba-01c5-90dc1cec56b1}">
32+
<Declaration><![CDATA[METHOD INTERNAL GetAssertionFailure : Tc2_System.T_MaxString]]></Declaration>
33+
<Implementation>
34+
<ST><![CDATA[GetAssertionFailure := AssertionFailure;]]></ST>
35+
</Implementation>
36+
</Method>
3037
<Method Name="GetAssertionMessage" Id="{273c4e89-faee-43b5-803d-428cdf75ac48}">
3138
<Declaration><![CDATA[METHOD INTERNAL GetAssertionMessage : T_MaxString]]></Declaration>
3239
<Implementation>
@@ -82,6 +89,18 @@ METHOD INTERNAL GetTestOrder : UINT(0..GVL_Param_TcUnit.MaxNumberOfTestsForEachT
8289
<ST><![CDATA[IsSkipped := TestIsSkipped;]]></ST>
8390
</Implementation>
8491
</Method>
92+
<Method Name="SetAssertionFailure" Id="{0c7899f5-2be3-0920-30bd-e2b4051f82f8}">
93+
<Declaration><![CDATA[(* Sets the assertion failure. If one already exists, it's not overwritten as we keep the first assertion in the test *)
94+
METHOD INTERNAL SetAssertionFailure
95+
VAR_INPUT
96+
AssertFailure : Tc2_System.T_MaxString;
97+
END_VAR]]></Declaration>
98+
<Implementation>
99+
<ST><![CDATA[IF Tc2_Standard.LEN(STR := AssertionFailure) = 0 THEN
100+
AssertionFailure := AssertFailure;
101+
END_IF]]></ST>
102+
</Implementation>
103+
</Method>
85104
<Method Name="SetAssertionMessage" Id="{05091715-93d7-47f7-9b6c-cb2511f88eb7}">
86105
<Declaration><![CDATA[(* Sets the assertion message. If one already exists, it's not overwritten as we keep the first assertion in the test *)
87106
METHOD INTERNAL SetAssertionMessage

TcUnit/TcUnit/POUs/FB_TestResults.TcPOU

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ IF StoringTestSuiteResultNumber <= GVL_TcUnit.NumberOfInitializedTestSuites AND
7474
(* Store the (first failed) assertion message *)
7575
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureMessage :=
7676
TestToBeStored.GetAssertionMessage();
77+
78+
(* Store the (first failed) assertion failure *)
79+
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureAssertion :=
80+
TestToBeStored.GetAssertionFailure();
7781
7882
(* Store the (first failed) assertion type *)
7983
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureType :=

0 commit comments

Comments
 (0)