Skip to content

Commit fc15f84

Browse files
authoredMar 13, 2025··
feat: Allow console output to be stored for either/both/none of testsuite and testcase (#164) (#165)
* feat: Allow console output to be stored for either/both/none of testsuite and testcase (#164) * feat: Update README for JUnit to include new StoreConsoleOutput values (#164)
1 parent b3e7cf8 commit fc15f84

File tree

3 files changed

+202
-63
lines changed

3 files changed

+202
-63
lines changed
 

‎src/JUnit.Xml.Package/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ We recommend this option for [GitLab](/docs/gitlab-recommendation.md) and [Circl
8686

8787
#### StoreConsoleOutput
8888

89-
You can use `StoreConsoleOutput` option to disable any `system-out` and `system-err` logs in both `testsuite`
90-
and `testcase` elements. By default, all console outputs are captured. Example usage:
89+
You can use `StoreConsoleOutput` option to disable any `system-out` and `system-err` logs in either `testsuite` or `testcase` elements or both. By default, all console outputs are captured. Example usage:
9190

9291
`dotnet test --logger:"junit;StoreConsoleOutput=false"`
9392

94-
NOTE: test attachments are always emitted in `system-out` even when above option is false.
93+
NOTE: test attachments are always emitted in `system-out` for tests cases even when above option is `false` or `testsuite`.
9594

9695
**v5.x and later behavior**
9796

@@ -107,6 +106,8 @@ would concatenate messages from all test results and information messages from a
107106

108107
- StoreConsoleOutput=true (default)
109108
- StoreConsoleOutput=false
109+
- StoreConsoleOutput=testsuite
110+
- StoreConsoleOutput=testcase
110111

111112
## License
112113

‎src/JUnit.Xml.TestLogger/JunitXmlSerializer.cs

+62-29
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Extension.Junit.Xml.TestLogger
1818
public class JunitXmlSerializer : ITestResultSerializer
1919
{
2020
// Dicionary keys for command line arguments.
21-
public const string MethodFormatKey = "MethodFormat";
22-
23-
public const string FailureBodyFormatKey = "FailureBodyFormat";
24-
25-
public const string StoreConsoleOutputKey = "StoreConsoleOutput";
21+
private const string MethodFormatKey = "MethodFormat";
22+
private const string FailureBodyFormatKey = "FailureBodyFormat";
23+
private const string StoreConsoleOutputKey = "StoreConsoleOutput";
2624

2725
private const string ResultStatusPassed = "Passed";
2826
private const string ResultStatusFailed = "Failed";
@@ -58,13 +56,36 @@ public enum FailureBodyFormat
5856
Verbose,
5957
}
6058

59+
public enum StoreConsoleOutputConfiguration
60+
{
61+
/// <summary>
62+
/// Console output will be stored at both test suite and test case level.
63+
/// </summary>
64+
Both,
65+
66+
/// <summary>
67+
/// No console output will be stored.
68+
/// </summary>
69+
None,
70+
71+
/// <summary>
72+
/// Console output will be stored at test case level only.
73+
/// </summary>
74+
TestCase,
75+
76+
/// <summary>
77+
/// Console output will be stored at test suite level only.
78+
/// </summary>
79+
TestSuite
80+
}
81+
6182
public IInputSanitizer InputSanitizer { get; } = new InputSanitizerXml();
6283

6384
public MethodFormat MethodFormatOption { get; private set; } = MethodFormat.Default;
6485

6586
public FailureBodyFormat FailureBodyFormatOption { get; private set; } = FailureBodyFormat.Default;
6687

67-
public bool StoreConsoleOutputOption { get; private set; } = true;
88+
public StoreConsoleOutputConfiguration StoreConsoleOutputOption { get; private set; } = StoreConsoleOutputConfiguration.Both;
6889

6990
public static IEnumerable<TestSuite> GroupTestSuites(IEnumerable<TestSuite> suites)
7091
{
@@ -252,34 +273,37 @@ private XElement CreateTestSuiteElement(List<TestResultInfo> results, TestRunCon
252273
{
253274
var testCaseElements = results.Select(a => this.CreateTestCaseElement(a));
254275

255-
StringBuilder stdOut = new StringBuilder();
256-
var frameworkInfo = messages.Where(x => x.Level == TestMessageLevel.Informational);
257-
if (frameworkInfo.Any())
276+
var stdOut = new StringBuilder();
277+
var stdErr = new StringBuilder();
278+
if (this.StoreConsoleOutputOption is StoreConsoleOutputConfiguration.Both or StoreConsoleOutputConfiguration.TestSuite)
258279
{
259-
stdOut.AppendLine(string.Empty);
260-
stdOut.AppendLine("Test Framework Informational Messages:");
261-
262-
foreach (var m in frameworkInfo)
280+
var frameworkInfo = messages.Where(x => x.Level == TestMessageLevel.Informational);
281+
if (frameworkInfo.Any())
263282
{
264-
stdOut.AppendLine(m.Message);
283+
stdOut.AppendLine(string.Empty);
284+
stdOut.AppendLine("Test Framework Informational Messages:");
285+
286+
foreach (var m in frameworkInfo)
287+
{
288+
stdOut.AppendLine(m.Message);
289+
}
265290
}
266-
}
267291

268-
StringBuilder stdErr = new StringBuilder();
269-
foreach (var m in messages.Where(x => x.Level != TestMessageLevel.Informational))
270-
{
271-
stdErr.AppendLine($"{m.Level} - {m.Message}");
292+
foreach (var m in messages.Where(x => x.Level != TestMessageLevel.Informational))
293+
{
294+
stdErr.AppendLine($"{m.Level} - {m.Message}");
295+
}
272296
}
273297

274298
// Adding required properties, system-out, and system-err elements in the correct
275-
// positions as required by the xsd. In system-out collapse consequtive newlines to a
299+
// positions as required by the xsd. In system-out collapse consecutive newlines to a
276300
// single newline.
277301
var element = new XElement(
278302
"testsuite",
279303
new XElement("properties"),
280304
testCaseElements,
281-
new XElement("system-out", this.StoreConsoleOutputOption ? stdOut.ToString() : string.Empty),
282-
new XElement("system-err", this.StoreConsoleOutputOption ? stdErr.ToString() : string.Empty));
305+
new XElement("system-out", stdOut.ToString()),
306+
new XElement("system-err", stdErr.ToString()));
283307

284308
element.SetAttributeValue("name", Path.GetFileName(results.First().AssemblyPath));
285309

@@ -358,9 +382,9 @@ private XElement CreateTestCaseElement(TestResultInfo result)
358382
}
359383

360384
// Add stdout and stderr to the testcase element
361-
StringBuilder stdOut = new StringBuilder();
362-
StringBuilder stdErr = new StringBuilder();
363-
if (this.StoreConsoleOutputOption)
385+
var stdOut = new StringBuilder();
386+
var stdErr = new StringBuilder();
387+
if (this.StoreConsoleOutputOption is StoreConsoleOutputConfiguration.Both or StoreConsoleOutputConfiguration.TestCase)
364388
{
365389
// Store the system-out and system-err only if store console output is enabled
366390
foreach (var m in result.Messages)
@@ -443,13 +467,22 @@ private void Configure(LoggerConfiguration loggerConfiguration)
443467

444468
if (loggerConfiguration.Values.TryGetValue(StoreConsoleOutputKey, out string storeOutputValue))
445469
{
446-
if (string.Equals(storeOutputValue.Trim(), "true", StringComparison.OrdinalIgnoreCase))
470+
storeOutputValue = storeOutputValue.Trim();
471+
if (string.Equals(storeOutputValue, "true", StringComparison.OrdinalIgnoreCase))
472+
{
473+
this.StoreConsoleOutputOption = StoreConsoleOutputConfiguration.Both;
474+
}
475+
else if (string.Equals(storeOutputValue, "false", StringComparison.OrdinalIgnoreCase))
476+
{
477+
this.StoreConsoleOutputOption = StoreConsoleOutputConfiguration.None;
478+
}
479+
else if (string.Equals(storeOutputValue, "testcase", StringComparison.OrdinalIgnoreCase))
447480
{
448-
this.StoreConsoleOutputOption = true;
481+
this.StoreConsoleOutputOption = StoreConsoleOutputConfiguration.TestCase;
449482
}
450-
else if (string.Equals(storeOutputValue.Trim(), "false", StringComparison.OrdinalIgnoreCase))
483+
else if (string.Equals(storeOutputValue, "testsuite", StringComparison.OrdinalIgnoreCase))
451484
{
452-
this.StoreConsoleOutputOption = false;
485+
this.StoreConsoleOutputOption = StoreConsoleOutputConfiguration.TestSuite;
453486
}
454487
else
455488
{

‎test/JUnit.Xml.TestLogger.AcceptanceTests/JUnitTestLoggerStoreConsoleOutputOptionsAcceptanceTests.cs

+136-31
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
namespace JUnit.Xml.TestLogger.AcceptanceTests
55
{
6-
using System;
7-
using System.IO;
8-
using System.Linq;
96
using System.Xml.Linq;
107
using System.Xml.XPath;
118
using global::TestLogger.Fixtures;
@@ -22,8 +19,6 @@ namespace JUnit.Xml.TestLogger.AcceptanceTests
2219
[TestClass]
2320
public class JUnitTestLoggerStoreConsoleOutputOptionsAcceptanceTests
2421
{
25-
private const string AssetName = "JUnit.Xml.TestLogger.NetCore.Tests";
26-
2722
[TestMethod]
2823
public void StoreConsoleOutput_Default_ContainsConsoleOut()
2924
{
@@ -35,14 +30,18 @@ public void StoreConsoleOutput_Default_ContainsConsoleOut()
3530
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-default-test-results.xml");
3631

3732
XDocument resultsXml = XDocument.Load(resultsFile);
38-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
3933

40-
Assert.IsTrue(node.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
41-
Assert.IsTrue(node.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
42-
Assert.IsTrue(node.Value.Contains("{EEEE1DA6-6296-4486-BDA5-A50A19672F0F}"));
43-
Assert.IsTrue(node.Value.Contains("{C33FF4B5-75E1-4882-B968-DF9608BFE7C2}"));
34+
var passedTestCaseStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='PassTest11']/system-out");
35+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
36+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
37+
38+
var testSuiteStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
39+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
40+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
41+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{EEEE1DA6-6296-4486-BDA5-A50A19672F0F}"));
42+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{C33FF4B5-75E1-4882-B968-DF9608BFE7C2}"));
4443

45-
this.TestCaseShouldHaveStdoutAndAttachment(resultsXml, "PassTest11");
44+
TestCaseShouldHaveAttachmentInStandardOut(resultsXml, "PassTest11");
4645
}
4746

4847
[TestMethod]
@@ -56,10 +55,14 @@ public void StoreConsoleOutput_Default_ContainsConsoleErr()
5655
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-default-test-results.xml");
5756

5857
XDocument resultsXml = XDocument.Load(resultsFile);
59-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
6058

61-
Assert.IsTrue(node.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
62-
Assert.IsTrue(node.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
59+
var failedTestCaseStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='FailTest11']/system-err");
60+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
61+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
62+
63+
var testSuiteStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
64+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
65+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
6366
}
6467

6568
[TestMethod]
@@ -73,14 +76,18 @@ public void StoreConsoleOutput_True_ContainsConsoleOut()
7376
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-true-test-results.xml");
7477

7578
XDocument resultsXml = XDocument.Load(resultsFile);
76-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
7779

78-
Assert.IsTrue(node.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
79-
Assert.IsTrue(node.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
80-
Assert.IsTrue(node.Value.Contains("{EEEE1DA6-6296-4486-BDA5-A50A19672F0F}"));
81-
Assert.IsTrue(node.Value.Contains("{C33FF4B5-75E1-4882-B968-DF9608BFE7C2}"));
80+
var passedTestCaseStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='PassTest11']/system-out");
81+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
82+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
83+
84+
var testSuiteStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
85+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
86+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
87+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{EEEE1DA6-6296-4486-BDA5-A50A19672F0F}"));
88+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{C33FF4B5-75E1-4882-B968-DF9608BFE7C2}"));
8289

83-
this.TestCaseShouldHaveStdoutAndAttachment(resultsXml, "PassTest11");
90+
TestCaseShouldHaveAttachmentInStandardOut(resultsXml, "PassTest11");
8491
}
8592

8693
[TestMethod]
@@ -94,14 +101,18 @@ public void StoreConsoleOutput_True_ContainsConsoleErr()
94101
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-true-test-results.xml");
95102

96103
XDocument resultsXml = XDocument.Load(resultsFile);
97-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
98104

99-
Assert.IsTrue(node.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
100-
Assert.IsTrue(node.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
105+
var failedTestCaseStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='FailTest11']/system-err");
106+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
107+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
108+
109+
var testSuiteStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
110+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
111+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
101112
}
102113

103114
[TestMethod]
104-
public void StoreConsoleOutput_False_ContainsConsoleOut()
115+
public void StoreConsoleOutput_False_DoesNotContainConsoleOut()
105116
{
106117
var loggerArgs = "junit;LogFilePath=output-false-test-results.xml;StoreConsoleOutput=false";
107118

@@ -111,15 +122,19 @@ public void StoreConsoleOutput_False_ContainsConsoleOut()
111122
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-false-test-results.xml");
112123

113124
XDocument resultsXml = XDocument.Load(resultsFile);
114-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
115125

116-
Assert.IsTrue(node.Value.Equals(string.Empty));
126+
var passedTestCaseStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='PassTest11']/system-out");
127+
Assert.IsFalse(passedTestCaseStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
128+
Assert.IsFalse(passedTestCaseStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
129+
130+
var testSuiteStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
131+
Assert.IsTrue(testSuiteStdOutNode.Value.Equals(string.Empty));
117132

118-
this.TestCaseShouldHaveStdoutAndAttachment(resultsXml, "PassTest11");
133+
TestCaseShouldHaveAttachmentInStandardOut(resultsXml, "PassTest11");
119134
}
120135

121136
[TestMethod]
122-
public void StoreConsoleOutput_False_ContainsConsoleErr()
137+
public void StoreConsoleOutput_False_DoesNotContainConsoleErr()
123138
{
124139
var loggerArgs = "junit;LogFilePath=output-false-test-results.xml;StoreConsoleOutput=false";
125140

@@ -129,12 +144,102 @@ public void StoreConsoleOutput_False_ContainsConsoleErr()
129144
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-false-test-results.xml");
130145

131146
XDocument resultsXml = XDocument.Load(resultsFile);
132-
var node = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
133147

134-
Assert.IsTrue(node.Value.Equals(string.Empty));
148+
var failedTestCaseStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='FailTest11']/system-err");
149+
Assert.IsNull(failedTestCaseStdErrNode);
150+
151+
var testSuiteStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
152+
Assert.IsTrue(testSuiteStdErrNode.Value.Equals(string.Empty));
153+
}
154+
155+
[TestMethod]
156+
public void StoreConsoleOutput_TestSuite_ContainsConsoleOutOnlyForTestSuite()
157+
{
158+
var loggerArgs = "junit;LogFilePath=output-testsuite-test-results.xml;StoreConsoleOutput=testsuite";
159+
160+
var resultsFile = DotnetTestFixture
161+
.Create()
162+
.WithBuild()
163+
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-testsuite-test-results.xml");
164+
165+
XDocument resultsXml = XDocument.Load(resultsFile);
166+
167+
var passedTestCaseStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='PassTest11']/system-out");
168+
Assert.IsFalse(passedTestCaseStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
169+
Assert.IsFalse(passedTestCaseStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
170+
171+
var testSuiteStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
172+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
173+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
174+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{EEEE1DA6-6296-4486-BDA5-A50A19672F0F}"));
175+
Assert.IsTrue(testSuiteStdOutNode.Value.Contains("{C33FF4B5-75E1-4882-B968-DF9608BFE7C2}"));
176+
177+
TestCaseShouldHaveAttachmentInStandardOut(resultsXml, "PassTest11");
178+
}
179+
180+
[TestMethod]
181+
public void StoreConsoleOutput_TestSuite_ContainsConsoleErrOnlyForTestSuite()
182+
{
183+
var loggerArgs = "junit;LogFilePath=output-testsuite-test-results.xml;StoreConsoleOutput=testsuite";
184+
185+
var resultsFile = DotnetTestFixture
186+
.Create()
187+
.WithBuild()
188+
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-testsuite-test-results.xml");
189+
190+
XDocument resultsXml = XDocument.Load(resultsFile);
191+
192+
var failedTestCaseStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='FailTest11']/system-err");
193+
Assert.IsNull(failedTestCaseStdErrNode);
194+
195+
var testSuiteStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
196+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
197+
Assert.IsTrue(testSuiteStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
198+
}
199+
200+
[TestMethod]
201+
public void StoreConsoleOutput_TestCase_ContainsConsoleOutOnlyForTestCase()
202+
{
203+
var loggerArgs = "junit;LogFilePath=output-testcase-test-results.xml;StoreConsoleOutput=testcase";
204+
205+
var resultsFile = DotnetTestFixture
206+
.Create()
207+
.WithBuild()
208+
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-testcase-test-results.xml");
209+
210+
XDocument resultsXml = XDocument.Load(resultsFile);
211+
212+
var passedTestCaseStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='PassTest11']/system-out");
213+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{2010CAE3-7BC0-4841-A5A3-7D5F947BB9FB}"));
214+
Assert.IsTrue(passedTestCaseStdOutNode.Value.Contains("{998AC9EC-7429-42CD-AD55-72037E7AF3D8}"));
215+
216+
var testSuiteStdOutNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-out");
217+
Assert.IsTrue(testSuiteStdOutNode.Value.Equals(string.Empty));
218+
219+
TestCaseShouldHaveAttachmentInStandardOut(resultsXml, "PassTest11");
220+
}
221+
222+
[TestMethod]
223+
public void StoreConsoleOutput_TestCase_ContainsConsoleErrOnlyForTestCase()
224+
{
225+
var loggerArgs = "junit;LogFilePath=output-testcase-test-results.xml;StoreConsoleOutput=testcase";
226+
227+
var resultsFile = DotnetTestFixture
228+
.Create()
229+
.WithBuild()
230+
.Execute("JUnit.Xml.TestLogger.NetCore.Tests", loggerArgs, collectCoverage: false, "output-testcase-test-results.xml");
231+
232+
XDocument resultsXml = XDocument.Load(resultsFile);
233+
234+
var failedTestCaseStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/*[@name='FailTest11']/system-err");
235+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{D46DFA10-EEDD-49E5-804D-FE43051331A7}"));
236+
Assert.IsTrue(failedTestCaseStdErrNode.Value.Contains("{33F5FD22-6F40-499D-98E4-481D87FAEAA1}"));
237+
238+
var testSuiteStdErrNode = resultsXml.XPathSelectElement("/testsuites/testsuite/system-err");
239+
Assert.IsTrue(testSuiteStdErrNode.Value.Equals(string.Empty));
135240
}
136241

137-
private void TestCaseShouldHaveStdoutAndAttachment(XDocument resultsXml, string testcaseName)
242+
private static void TestCaseShouldHaveAttachmentInStandardOut(XDocument resultsXml, string testcaseName)
138243
{
139244
var node = resultsXml.XPathSelectElement($"/testsuites/testsuite/*[@name='{testcaseName}']/system-out");
140245

0 commit comments

Comments
 (0)
Please sign in to comment.