Skip to content

Commit 4a4a538

Browse files
authored
Cherry-pick fix skipped Test isn't shown as skipped/not executed in Trx Report (#3787)
1 parent 60dc7a5 commit 4a4a538

File tree

5 files changed

+49
-26
lines changed

5 files changed

+49
-26
lines changed

src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxDataConsumer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ internal sealed class TrxReportGenerator :
4848
private DateTimeOffset? _testStartTime;
4949
private int _failedTestsCount;
5050
private int _passedTestsCount;
51+
private int _notExecutedTestsCount;
5152
private bool _adapterSupportTrxCapability;
5253

5354
public TrxReportGenerator(
@@ -128,6 +129,7 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
128129
else if (nodeState is SkippedTestNodeStateProperty)
129130
{
130131
_tests.Add(nodeChangedMessage);
132+
_notExecutedTestsCount++;
131133
}
132134

133135
break;
@@ -225,7 +227,7 @@ public async Task OnTestSessionFinishingAsync(SessionUid sessionUid, Cancellatio
225227
ApplicationStateGuard.Ensure(_testStartTime is not null);
226228

227229
TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptionsService, _configuration,
228-
_clock, _tests.ToArray(), _failedTestsCount, _passedTestsCount, _artifactsByExtension, _artifactsByTestNode,
230+
_clock, _tests.ToArray(), _failedTestsCount, _passedTestsCount, _notExecutedTestsCount, _artifactsByExtension, _artifactsByTestNode,
229231
_adapterSupportTrxCapability, _testFramework, _testStartTime.Value, cancellationToken);
230232
string reportFileName = await trxReportGeneratorEngine.GenerateReportAsync();
231233

src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxProcessLifetimeHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public async Task OnTestHostProcessExitedAsync(ITestHostProcessInformation testH
158158
if (!testHostProcessInformation.HasExitedGracefully)
159159
{
160160
TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptions, _configuration,
161-
_clock, [], 0, 0,
161+
_clock, [], 0, 0, 0,
162162
artifacts,
163163
new Dictionary<TestNodeUid, List<SessionFileArtifact>>(),
164164
adapterSupportTrxCapability: null,
@@ -188,7 +188,7 @@ await _messageBus.PublishAsync(
188188
if (_fileArtifacts.Count > 0)
189189
{
190190
TrxReportEngine trxReportGeneratorEngine = new(_testApplicationModuleInfo, _environment, _commandLineOptions, _configuration,
191-
_clock, [], 0, 0,
191+
_clock, [], 0, 0, 0,
192192
artifacts,
193193
new Dictionary<TestNodeUid, List<SessionFileArtifact>>(),
194194
false,

src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ internal sealed partial class TrxReportEngine
9494
private readonly TestNodeUpdateMessage[] _testNodeUpdatedMessages;
9595
private readonly int _failedTestsCount;
9696
private readonly int _passedTestsCount;
97+
private readonly int _notExecutedTestsCount;
9798
private readonly Dictionary<IExtension, List<SessionFileArtifact>> _artifactsByExtension;
9899
private readonly Dictionary<TestNodeUid, List<SessionFileArtifact>> _artifactsByTestNode;
99100
private readonly bool? _adapterSupportTrxCapability;
@@ -104,27 +105,28 @@ internal sealed partial class TrxReportEngine
104105
private readonly IFileSystem _fileSystem;
105106
private readonly bool _isCopyingFileAllowed;
106107

107-
public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken)
108-
: this(
109-
new SystemFileSystem(),
110-
testApplicationModuleInfo,
111-
environment,
112-
commandLineOptionsService,
113-
configuration,
114-
clock,
115-
testNodeUpdatedMessages,
116-
failedTestsCount,
117-
passedTestsCount,
118-
artifactsByExtension,
119-
artifactsByTestNode,
120-
adapterSupportTrxCapability,
121-
testFrameworkAdapter,
122-
testStartTime,
123-
cancellationToken)
108+
public TrxReportEngine(ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken)
109+
: this(
110+
new SystemFileSystem(),
111+
testApplicationModuleInfo,
112+
environment,
113+
commandLineOptionsService,
114+
configuration,
115+
clock,
116+
testNodeUpdatedMessages,
117+
failedTestsCount,
118+
passedTestsCount,
119+
notExecutedTestsCount,
120+
artifactsByExtension,
121+
artifactsByTestNode,
122+
adapterSupportTrxCapability,
123+
testFrameworkAdapter,
124+
testStartTime,
125+
cancellationToken)
124126
{
125127
}
126128

127-
internal TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken, bool isCopyingFileAllowed = true)
129+
public TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo testApplicationModuleInfo, IEnvironment environment, ICommandLineOptions commandLineOptionsService, IConfiguration configuration, IClock clock, TestNodeUpdateMessage[] testNodeUpdatedMessages, int failedTestsCount, int passedTestsCount, int notExecutedTestsCount, Dictionary<IExtension, List<SessionFileArtifact>> artifactsByExtension, Dictionary<TestNodeUid, List<SessionFileArtifact>> artifactsByTestNode, bool? adapterSupportTrxCapability, ITestFramework testFrameworkAdapter, DateTimeOffset testStartTime, CancellationToken cancellationToken, bool isCopyingFileAllowed = true)
128130
{
129131
_testApplicationModuleInfo = testApplicationModuleInfo;
130132
_environment = environment;
@@ -134,6 +136,7 @@ internal TrxReportEngine(IFileSystem fileSystem, ITestApplicationModuleInfo test
134136
_testNodeUpdatedMessages = testNodeUpdatedMessages;
135137
_failedTestsCount = failedTestsCount;
136138
_passedTestsCount = passedTestsCount;
139+
_notExecutedTestsCount = notExecutedTestsCount;
137140
_artifactsByExtension = artifactsByExtension;
138141
_artifactsByTestNode = artifactsByTestNode;
139142
_adapterSupportTrxCapability = adapterSupportTrxCapability;
@@ -302,7 +305,7 @@ private async Task AddResultSummaryAsync(XElement testRun, string resultSummaryO
302305
new XAttribute("inconclusive", 0),
303306
new XAttribute("passedButRunAborted", 0),
304307
new XAttribute("notRunnable", 0),
305-
new XAttribute("notExecuted", 0),
308+
new XAttribute("notExecuted", _notExecutedTestsCount),
306309
new XAttribute("disconnected", 0),
307310
new XAttribute("warning", 0),
308311
new XAttribute("completed", 0),

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task Trx_WhenSkipTest_ItAppearsAsExpectedInsideTheTrx(string tfm)
8181
Assert.That(trxContent.Contains(@"<UnitTest name=""TestMethod1"), trxContent);
8282
Assert.That(trxContent.Contains(@"<TestEntry "), trxContent);
8383
Assert.That(trxContent.Contains("""<ResultSummary outcome="Completed">"""), trxContent);
84-
Assert.That(trxContent.Contains("""<Counters total="2" executed="0" passed="0" failed="0" error="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />"""), trxContent);
84+
Assert.That(trxContent.Contains("""<Counters total="2" executed="0" passed="0" failed="0" error="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="2" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />"""), trxContent);
8585
}
8686

8787
[ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))]

test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ public async Task TrxReportEngine_GenerateReportAsyncWithNullAdapterSupportTrxCa
5151
Assert.IsFalse(trxContent.Contains(@"className="));
5252
}
5353

54+
public async Task TrxReportEngine_GenerateReportAsyncWithNotExecutedTests_TrxExecutedTestsCountHasIt()
55+
{
56+
// Arrange
57+
using MemoryFileStream memoryStream = new();
58+
PropertyBag propertyBag = new(new PassedTestNodeStateProperty());
59+
TrxReportEngine trxReportEngine = GenerateTrxReportEngine(1, 0, propertyBag, memoryStream, notExecutedTestsCount: 1);
60+
61+
// Act
62+
string fileName = await trxReportEngine.GenerateReportAsync(keepReportFileStreamOpen: true);
63+
64+
// Assert
65+
AssertExpectedTrxFileName(fileName);
66+
XDocument xml = GetTrxContent(memoryStream);
67+
AssertTrxOutcome(xml, "Completed");
68+
string trxContent = xml.ToString();
69+
Assert.IsTrue(trxContent.Contains(@"notExecuted=""1"""));
70+
}
71+
5472
public async Task TrxReportEngine_GenerateReportAsync_WithArgumentTrxReportFileName_FileIsCorrectlyGenerated()
5573
{
5674
// Arrange
@@ -359,7 +377,7 @@ public async Task TrxReportEngine_GenerateReportAsync_FileAlreadyExists_WillRetr
359377
_ = _environmentMock.SetupGet(_ => _.MachineName).Returns("MachineName");
360378
_ = _testApplicationModuleInfoMock.Setup(_ => _.GetCurrentTestApplicationFullPath()).Returns("TestAppPath");
361379
TrxReportEngine trxReportEngine = new(_fileSystem.Object, _testApplicationModuleInfoMock.Object, _environmentMock.Object, _commandLineOptionsMock.Object,
362-
_configurationMock.Object, _clockMock.Object, [], 0, 0,
380+
_configurationMock.Object, _clockMock.Object, [], 0, 0, 0,
363381
_artifactsByExtension, _artifactsByTestNode, true, _testFrameworkMock.Object, DateTime.UtcNow, CancellationToken.None,
364382
isCopyingFileAllowed: false);
365383

@@ -394,7 +412,7 @@ private static void AssertExpectedTrxFileName(string fileName)
394412
=> Assert.IsTrue(fileName.Equals("_MachineName_0001-01-01_00_00_00.000.trx", StringComparison.Ordinal));
395413

396414
private TrxReportEngine GenerateTrxReportEngine(int passedTestsCount, int failedTestsCount, PropertyBag propertyBag, MemoryFileStream memoryStream,
397-
bool? adapterSupportTrxCapability = null)
415+
bool? adapterSupportTrxCapability = null, int notExecutedTestsCount = 0)
398416
{
399417
var testNode = new TestNodeUpdateMessage(
400418
new SessionUid("1"),
@@ -414,7 +432,7 @@ private TrxReportEngine GenerateTrxReportEngine(int passedTestsCount, int failed
414432
_ = _testApplicationModuleInfoMock.Setup(_ => _.GetCurrentTestApplicationFullPath()).Returns("TestAppPath");
415433

416434
return new TrxReportEngine(_fileSystem.Object, _testApplicationModuleInfoMock.Object, _environmentMock.Object, _commandLineOptionsMock.Object,
417-
_configurationMock.Object, _clockMock.Object, testNodeUpdatedMessages, failedTestsCount, passedTestsCount,
435+
_configurationMock.Object, _clockMock.Object, testNodeUpdatedMessages, failedTestsCount, passedTestsCount, notExecutedTestsCount,
418436
_artifactsByExtension, _artifactsByTestNode, adapterSupportTrxCapability, _testFrameworkMock.Object, testStartTime, cancellationToken,
419437
isCopyingFileAllowed: false);
420438
}

0 commit comments

Comments
 (0)