Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xUnitXmlPublisher): Include assertion message in test output #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TcUnit/TcUnit/DUTs/ST_TestCaseResult.TcDUT
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ STRUCT
TestIsFailed : BOOL;
TestIsSkipped : BOOL;
FailureMessage : T_MaxString;
FailureAssertion : Tc2_System.T_MaxString;
FailureType : E_AssertionType;
NumberOfAsserts : UINT;
Duration : LREAL; // in seconds
Expand Down
2 changes: 1 addition & 1 deletion TcUnit/TcUnit/ITFs/I_AssertMessageFormatter.TcIO
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Declaration><![CDATA[INTERFACE I_AssertMessageFormatter
]]></Declaration>
<Method Name="LogAssertFailure" Id="{35efab01-6ac8-46a5-a5e1-adb4f1f5f9b2}">
<Declaration><![CDATA[METHOD LogAssertFailure
<Declaration><![CDATA[METHOD LogAssertFailure : Tc2_System.T_MaxString
VAR_INPUT
Expected : T_MaxString;
Actual : T_MaxString;
Expand Down
7 changes: 5 additions & 2 deletions TcUnit/TcUnit/POUs/FB_AdsAssertMessageFormatter.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FUNCTION_BLOCK FB_AdsAssertMessageFormatter IMPLEMENTS I_AssertMessageFormatter]
<ST><![CDATA[]]></ST>
</Implementation>
<Method Name="LogAssertFailure" Id="{48cbc6b0-5380-44b8-a045-57b6ad9f189d}">
<Declaration><![CDATA[METHOD PUBLIC LogAssertFailure
<Declaration><![CDATA[METHOD PUBLIC LogAssertFailure : Tc2_System.T_MaxString
VAR_INPUT
Expected : T_MaxString;
Actual : T_MaxString;
Expand All @@ -24,7 +24,7 @@ VAR
TestInstancePathFinal : T_MaxString;
ReturnValue : DINT;
TestInstancePathProcessed : T_MaxString;
MessageProcessed : T_MaxString;
MessageProcessed : Tc2_System.T_MaxString;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TestInstancePathCleaned := F_RemoveInstancePathAndProjectNameFromTestInstancePath(TestInstancePath);
Expand All @@ -34,10 +34,13 @@ TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := '$'');
IF LEN(STR := Expected) > 0 THEN
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', EXP: ');
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := Expected);
LogAssertFailure := Tc2_Standard.CONCAT('EXP: ', Expected);
END_IF
IF LEN(STR := Actual) > 0 THEN
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', ACT: ');
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := Actual);
LogAssertFailure := Tc2_Standard.CONCAT(LogAssertFailure, ', ACT: ');
LogAssertFailure := Tc2_Standard.CONCAT(LogAssertFailure, Actual);
END_IF
IF LEN(STR := Message) > 0 THEN
TestInstancePathFinal := CONCAT(STR1 := TestInstancePathFinal, STR2 := ', MSG: %s');
Expand Down
19 changes: 19 additions & 0 deletions TcUnit/TcUnit/POUs/FB_Test.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ VAR
(* Failure parameters. If TestIsFailed is TRUE, the other parameters will hold values as well *)
TestIsFailed : BOOL; // Indication of whether this test has at least one failed assert
AssertionMessage : T_MaxString; // Assertion message for the first assertion in this test
AssertionFailure : Tc2_System.T_MaxString; // Assertion failure for the first assertion in this test
AssertionType : E_AssertionType; // Assertion type for the first assertion in this test

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
Expand All @@ -27,6 +28,12 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[]]></ST>
</Implementation>
<Method Name="GetAssertionFailure" Id="{fca1dda8-8d75-01ba-01c5-90dc1cec56b1}">
<Declaration><![CDATA[METHOD INTERNAL GetAssertionFailure : Tc2_System.T_MaxString]]></Declaration>
<Implementation>
<ST><![CDATA[GetAssertionFailure := AssertionFailure;]]></ST>
</Implementation>
</Method>
<Method Name="GetAssertionMessage" Id="{273c4e89-faee-43b5-803d-428cdf75ac48}">
<Declaration><![CDATA[METHOD INTERNAL GetAssertionMessage : T_MaxString]]></Declaration>
<Implementation>
Expand Down Expand Up @@ -82,6 +89,18 @@ METHOD INTERNAL GetTestOrder : UINT(0..GVL_Param_TcUnit.MaxNumberOfTestsForEachT
<ST><![CDATA[IsSkipped := TestIsSkipped;]]></ST>
</Implementation>
</Method>
<Method Name="SetAssertionFailure" Id="{0c7899f5-2be3-0920-30bd-e2b4051f82f8}">
<Declaration><![CDATA[(* Sets the assertion failure. If one already exists, it's not overwritten as we keep the first assertion in the test *)
METHOD INTERNAL SetAssertionFailure
VAR_INPUT
AssertFailure : Tc2_System.T_MaxString;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[IF Tc2_Standard.LEN(STR := AssertionFailure) = 0 THEN
AssertionFailure := AssertFailure;
END_IF]]></ST>
</Implementation>
</Method>
<Method Name="SetAssertionMessage" Id="{05091715-93d7-47f7-9b6c-cb2511f88eb7}">
<Declaration><![CDATA[(* Sets the assertion message. If one already exists, it's not overwritten as we keep the first assertion in the test *)
METHOD INTERNAL SetAssertionMessage
Expand Down
4 changes: 4 additions & 0 deletions TcUnit/TcUnit/POUs/FB_TestResults.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ IF StoringTestSuiteResultNumber <= GVL_TcUnit.NumberOfInitializedTestSuites AND
(* Store the (first failed) assertion message *)
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureMessage :=
TestToBeStored.GetAssertionMessage();

(* Store the (first failed) assertion failure *)
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureAssertion :=
TestToBeStored.GetAssertionFailure();

(* Store the (first failed) assertion type *)
TestSuiteResults.TestSuiteResults[StoringTestSuiteResultNumber].TestCaseResults[TestsInTestSuiteCounter].FailureType :=
Expand Down
Loading