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

Opt-in to emit error message in CDATA-element of failure-element #108

Merged
merged 1 commit into from
Jul 8, 2022
Merged
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
3 changes: 3 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ This can be configured via environment varialbes (note: if omitted, the default
| failure | `TRX2JUNIT_JENKINS_TESTCASE_STATUS_FAILURE` | `0` |
| skipped | `TRX2JUNIT_JENKINS_TESTCASE_STATUS_SKIPPED` | not set |

With environment variable `TRX2JUNIT_JUNIT_ERROR_MESSAGE_IN_CDATA` set, the error message from a failing test will be repeated in the _CDATA_-content of the `<failure>` element.
See [this comment](https://github.com/gfoidl/trx2junit/issues/104#issuecomment-1178852241) for further info.

### junit to trx

With option `--junit2trx` a conversion from _junit_ to _trx_ can be performed.
Expand Down
9 changes: 5 additions & 4 deletions source/trx2junit.Core/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace gfoidl.Trx2Junit.Core;

internal static class Globals
{
public static readonly string JUnitTestCaseStatusSuccess = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_SUCCESS") ?? "1";
public static readonly string JUnitTestCaseStatusFailure = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_FAILURE") ?? "0";
public static readonly string? JUnitTestCaseStatusSkipped = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_SKIPPED");
public static readonly bool VectorsEnabled = GetEnvironmentVariable("TRX2JUNIT_VECTORS_ENABLED") != null;
public static readonly string JUnitTestCaseStatusSuccess = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_SUCCESS") ?? "1";
public static readonly string JUnitTestCaseStatusFailure = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_FAILURE") ?? "0";
public static readonly string? JUnitTestCaseStatusSkipped = GetEnvironmentVariable("TRX2JUNIT_JENKINS_TESTCASE_STATUS_SKIPPED");
public static readonly bool JUnitErrorMessageRepeatCData = GetEnvironmentVariable("TRX2JUNIT_JUNIT_ERROR_MESSAGE_IN_CDATA") != null;
public static readonly bool VectorsEnabled = GetEnvironmentVariable("TRX2JUNIT_VECTORS_ENABLED") != null;
//---------------------------------------------------------------------
private static string? GetEnvironmentVariable(string envVariableName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ private void AddTestCase(XElement xTestSuite, JUnitTestCase testCase)
}
else if (testCase.Error != null)
{
string failureContent = $"{testCase.Error.Message}\n{testCase.Error.StackTrace?.TrimEnd()}";
string? failureContent = Globals.JUnitErrorMessageRepeatCData
? $"{testCase.Error.Message}\n{testCase.Error.StackTrace?.TrimEnd()}"
: testCase.Error.StackTrace?.TrimEnd();

xTestCase.Add(new XElement("failure",
new XCData(failureContent),
XElement xFailure = new ("failure",
new XAttribute("message", testCase.Error.Message!),
new XAttribute("type" , testCase.Error.Type!)
));
);

if (failureContent is not null)
{
xFailure.Add(new XCData(failureContent));
}

xTestCase.Add(xFailure);
xTestCase.Add(new XAttribute("status", Globals.JUnitTestCaseStatusFailure));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public void TrxUnitTestResult_with_error___failure_element_populated()
{
Assert.AreEqual("Failing for demo purposes", failure.Attribute("message").Value);

string expectedContent = @"<![CDATA[Failing for demo purposes
at NUnitSample.SimpleTests.Failing_test() in D:\Work-Git\github\Mini\trx2junit\samples\NUnitSample\SimpleTests.cs:line 21]]>";
string expectedContent = @"<![CDATA[ at NUnitSample.SimpleTests.Failing_test() in D:\Work-Git\github\Mini\trx2junit\samples\NUnitSample\SimpleTests.cs:line 21]]>";
string actualContent = failure.LastNode.ToString();

expectedContent = NormalizeLineEndings(expectedContent);
Expand Down