Skip to content

Commit 4a566a4

Browse files
Dotnet test integration (first part) (#44268)
Co-authored-by: Mariam Abdullah <[email protected]>
1 parent 26fd6d1 commit 4a566a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6011
-31
lines changed

Directory.Packages.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
<PackageVersion Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(MicrosoftTemplateEngineOrchestratorRunnableProjectsPackageVersion)" />
6464
<PackageVersion Include="Microsoft.TemplateEngine.TestHelper" Version="$(MicrosoftTemplateEngineTestHelperPackageVersion)" />
6565
<PackageVersion Include="Microsoft.TemplateSearch.Common" Version="$(MicrosoftTemplateSearchCommonPackageVersion)" />
66-
<PackageVersion Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
67-
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />
6866
<PackageVersion Include="Microsoft.TestPlatform.Build" Version="$(MicrosoftTestPlatformBuildPackageVersion)" />
6967
<PackageVersion Include="Microsoft.TestPlatform.CLI" Version="$(MicrosoftTestPlatformCLIPackageVersion)" />
7068
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.4.16" />

eng/Version.Details.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,7 @@
634634
<Uri>https://github.com/dotnet/runtime</Uri>
635635
<Sha>e77011b31a3e5c47d931248a64b47f9b2d47853d</Sha>
636636
</Dependency>
637-
<Dependency Name="Microsoft.Testing.Platform" Version="1.6.0-preview.25059.14">
638-
<Uri>https://github.com/microsoft/testfx</Uri>
639-
<Sha>53488cf463d33882113ca7a6fbbb6f93e06251df</Sha>
640-
</Dependency>
641-
<Dependency Name="MSTest" Version="3.8.0-preview.25059.14">
637+
<Dependency Name="MSTest" Version="3.8.0-preview.25057.8">
642638
<Uri>https://github.com/microsoft/testfx</Uri>
643639
<Sha>53488cf463d33882113ca7a6fbbb6f93e06251df</Sha>
644640
</Dependency>

eng/Versions.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<UsingToolMicrosoftNetCompilers Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</UsingToolMicrosoftNetCompilers>
2929
<MicrosoftIORedistPackageVersion>6.0.1</MicrosoftIORedistPackageVersion>
3030
<FlagNetStandard1XDependencies Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</FlagNetStandard1XDependencies>
31-
<MicrosoftTestingPlatformVersion>1.6.0-preview.25059.14</MicrosoftTestingPlatformVersion>
3231
</PropertyGroup>
3332
<PropertyGroup Label="Servicing version information">
3433
<VersionFeature21>30</VersionFeature21>

src/Cli/dotnet/commands/dotnet-test/IPC/Models/TestResultMessages.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace Microsoft.DotNet.Tools.Test
55
{
66
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? StandardOutput, string? ErrorOutput, string? SessionUid);
77

8-
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? StandardOutput, string? ErrorOutput, string? SessionUid);
8+
internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, ExceptionMessage[]? Exceptions, string? StandardOutput, string? ErrorOutput, string? SessionUid);
9+
10+
internal sealed record ExceptionMessage(string? ErrorMessage, string? ErrorType, string? StackTrace);
911

1012
internal sealed record TestResultMessages(string? ExecutionId, SuccessfulTestResultMessage[] SuccessfulTestMessages, FailedTestResultMessage[] FailedTestMessages) : IRequest;
1113
}

src/Cli/dotnet/commands/dotnet-test/IPC/ObjectFieldIds.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ internal static class FailedTestResultMessageFieldsId
8585
public const ushort State = 3;
8686
public const ushort Duration = 4;
8787
public const ushort Reason = 5;
88-
public const ushort ErrorMessage = 6;
89-
public const ushort ErrorStackTrace = 7;
88+
public const ushort ExceptionMessageList = 6;
9089
public const ushort StandardOutput = 8;
9190
public const ushort ErrorOutput = 9;
9291
public const ushort SessionUid = 10;
9392
}
9493

94+
internal static class ExceptionMessageFieldsId
95+
{
96+
public const ushort ErrorMessage = 1;
97+
public const ushort ErrorType = 2;
98+
public const ushort StackTrace = 3;
99+
}
100+
95101
internal static class FileArtifactMessagesFieldsId
96102
{
97103
public const int MessagesSerializerId = 7;

src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/TestResultMessagesSerializer.cs

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
217217
int length = ReadInt(stream);
218218
for (int i = 0; i < length; i++)
219219
{
220-
string? uid = null, displayName = null, reason = null, sessionUid = null,
221-
errorMessage = null, errorStackTrace = null, standardOutput = null, errorOutput = null;
220+
string? uid = null, displayName = null, reason = null, sessionUid = null, standardOutput = null, errorOutput = null;
221+
List<ExceptionMessage> exceptionMessages = [];
222222
byte? state = null;
223223
long? duration = null;
224224

@@ -251,13 +251,44 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
251251
reason = ReadStringValue(stream, fieldSize);
252252
break;
253253

254-
case FailedTestResultMessageFieldsId.ErrorMessage:
255-
errorMessage = ReadStringValue(stream, fieldSize);
256-
break;
254+
case FailedTestResultMessageFieldsId.ExceptionMessageList:
255+
{
256+
int length2 = ReadInt(stream);
257+
for (int k = 0; k < length2; k++)
258+
{
257259

258-
case FailedTestResultMessageFieldsId.ErrorStackTrace:
259-
errorStackTrace = ReadStringValue(stream, fieldSize);
260-
break;
260+
int fieldCount2 = ReadShort(stream);
261+
262+
string? errorMessage = null;
263+
string? errorType = null;
264+
string? stackTrace = null;
265+
266+
for (int l = 0; l < fieldCount2; l++)
267+
{
268+
int fieldId2 = ReadShort(stream);
269+
int fieldSize2 = ReadInt(stream);
270+
271+
switch (fieldId2)
272+
{
273+
case ExceptionMessageFieldsId.ErrorMessage:
274+
errorMessage = ReadStringValue(stream, fieldSize2);
275+
break;
276+
277+
case ExceptionMessageFieldsId.ErrorType:
278+
errorType = ReadStringValue(stream, fieldSize2);
279+
break;
280+
281+
case ExceptionMessageFieldsId.StackTrace:
282+
stackTrace = ReadStringValue(stream, fieldSize2);
283+
break;
284+
}
285+
}
286+
287+
exceptionMessages.Add(new ExceptionMessage(errorMessage, errorType, stackTrace));
288+
}
289+
290+
break;
291+
}
261292

262293
case FailedTestResultMessageFieldsId.StandardOutput:
263294
standardOutput = ReadStringValue(stream, fieldSize);
@@ -277,7 +308,7 @@ private static List<FailedTestResultMessage> ReadFailedTestMessagesPayload(Strea
277308
}
278309
}
279310

280-
failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, errorMessage, errorStackTrace, standardOutput, errorOutput, sessionUid));
311+
failedTestResultMessages.Add(new FailedTestResultMessage(uid, displayName, state, duration, reason, exceptionMessages.ToArray(), standardOutput, errorOutput, sessionUid));
281312
}
282313

283314
return failedTestResultMessages;
@@ -354,8 +385,7 @@ private static void WriteFailedTestMessagesPayload(Stream stream, FailedTestResu
354385
WriteField(stream, FailedTestResultMessageFieldsId.State, failedTestResultMessage.State);
355386
WriteField(stream, FailedTestResultMessageFieldsId.Duration, failedTestResultMessage.Duration);
356387
WriteField(stream, FailedTestResultMessageFieldsId.Reason, failedTestResultMessage.Reason);
357-
WriteField(stream, FailedTestResultMessageFieldsId.ErrorMessage, failedTestResultMessage.ErrorMessage);
358-
WriteField(stream, FailedTestResultMessageFieldsId.ErrorStackTrace, failedTestResultMessage.ErrorStackTrace);
388+
WriteExceptionMessagesPayload(stream, failedTestResultMessage.Exceptions);
359389
WriteField(stream, FailedTestResultMessageFieldsId.StandardOutput, failedTestResultMessage.StandardOutput);
360390
WriteField(stream, FailedTestResultMessageFieldsId.ErrorOutput, failedTestResultMessage.ErrorOutput);
361391
WriteField(stream, FailedTestResultMessageFieldsId.SessionUid, failedTestResultMessage.SessionUid);
@@ -366,6 +396,35 @@ private static void WriteFailedTestMessagesPayload(Stream stream, FailedTestResu
366396
WriteAtPosition(stream, (int)(stream.Position - before), before - sizeof(int));
367397
}
368398

399+
private static void WriteExceptionMessagesPayload(Stream stream, ExceptionMessage[]? exceptionMessages)
400+
{
401+
if (exceptionMessages is null || exceptionMessages.Length == 0)
402+
{
403+
return;
404+
}
405+
406+
WriteShort(stream, FailedTestResultMessageFieldsId.ExceptionMessageList);
407+
408+
// We will reserve an int (4 bytes)
409+
// so that we fill the size later, once we write the payload
410+
WriteInt(stream, 0);
411+
412+
long before = stream.Position;
413+
WriteInt(stream, exceptionMessages.Length);
414+
foreach (ExceptionMessage exceptionMessage in exceptionMessages)
415+
{
416+
WriteShort(stream, GetFieldCount(exceptionMessage));
417+
418+
WriteField(stream, ExceptionMessageFieldsId.ErrorMessage, exceptionMessage.ErrorMessage);
419+
WriteField(stream, ExceptionMessageFieldsId.ErrorType, exceptionMessage.ErrorType);
420+
WriteField(stream, ExceptionMessageFieldsId.StackTrace, exceptionMessage.StackTrace);
421+
}
422+
423+
// NOTE: We are able to seek only if we are using a MemoryStream
424+
// thus, the seek operation is fast as we are only changing the value of a property
425+
WriteAtPosition(stream, (int)(stream.Position - before), before - sizeof(int));
426+
}
427+
369428
private static ushort GetFieldCount(TestResultMessages testResultMessages) =>
370429
(ushort)((testResultMessages.ExecutionId is null ? 0 : 1) +
371430
(IsNullOrEmpty(testResultMessages.SuccessfulTestMessages) ? 0 : 1) +
@@ -387,10 +446,14 @@ private static ushort GetFieldCount(FailedTestResultMessage failedTestResultMess
387446
(failedTestResultMessage.State is null ? 0 : 1) +
388447
(failedTestResultMessage.Duration is null ? 0 : 1) +
389448
(failedTestResultMessage.Reason is null ? 0 : 1) +
390-
(failedTestResultMessage.ErrorMessage is null ? 0 : 1) +
391-
(failedTestResultMessage.ErrorStackTrace is null ? 0 : 1) +
449+
(IsNullOrEmpty(failedTestResultMessage.Exceptions) ? 0 : 1) +
392450
(failedTestResultMessage.StandardOutput is null ? 0 : 1) +
393451
(failedTestResultMessage.ErrorOutput is null ? 0 : 1) +
394452
(failedTestResultMessage.SessionUid is null ? 0 : 1));
453+
454+
private static ushort GetFieldCount(ExceptionMessage exceptionMessage) =>
455+
(ushort)((exceptionMessage.ErrorMessage is null ? 0 : 1) +
456+
(exceptionMessage.ErrorType is null ? 0 : 1) +
457+
(exceptionMessage.StackTrace is null ? 0 : 1));
395458
}
396459
}

src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ Examples:
304304
<value>NAME="VALUE"</value>
305305
</data>
306306
<data name="NoSerializerRegisteredWithIdErrorMessage" xml:space="preserve">
307-
<value>No serializer registered with ID '{0}'</value>
307+
<value>No serializer registered with ID '{0}'</value>
308308
</data>
309309
<data name="NoSerializerRegisteredWithTypeErrorMessage" xml:space="preserve">
310-
<value>No serializer registered with type '{0}'</value>
310+
<value>No serializer registered with type '{0}'</value>
311311
</data>
312312
<data name="CmdMaxParallelTestModulesDescription" xml:space="preserve">
313313
<value>The max number of test modules that can run in parallel.</value>
@@ -332,6 +332,114 @@ Examples:
332332
<data name="CmdUnsupportedVSTestTestApplicationsDescription" xml:space="preserve">
333333
<value>Test application(s) that support VSTest are not supported.</value>
334334
</data>
335+
<data name="Aborted" xml:space="preserve">
336+
<value>Aborted</value>
337+
</data>
338+
<data name="ActiveTestsRunning_FullTestsCount" xml:space="preserve">
339+
<value>{0} tests running</value>
340+
</data>
341+
<data name="ActiveTestsRunning_MoreTestsCount" xml:space="preserve">
342+
<value>and {0} more</value>
343+
</data>
344+
<data name="Actual" xml:space="preserve">
345+
<value>Actual</value>
346+
</data>
347+
<data name="CancelledLowercase" xml:space="preserve">
348+
<value>canceled</value>
349+
</data>
350+
<data name="CancellingTestSession" xml:space="preserve">
351+
<value>Canceling the test session...</value>
352+
</data>
353+
<data name="ConsoleIsAlreadyInBatchingMode" xml:space="preserve">
354+
<value>Console is already in batching mode.</value>
355+
<comment>Exception that is thrown when console is already collecting input into a batch (into a string builder), and code asks to enable batching mode again.</comment>
356+
</data>
357+
<data name="DiscoveredTestsInAssembly" xml:space="preserve">
358+
<value>Discovered {0} tests in assembly</value>
359+
<comment>0 is count, the sentence is followed by the path of the assebly</comment>
360+
</data>
361+
<data name="DiscoveringTestsFrom" xml:space="preserve">
362+
<value>Discovering tests from</value>
363+
</data>
364+
<data name="ExitCode" xml:space="preserve">
365+
<value>Exit code</value>
366+
</data>
367+
<data name="Expected" xml:space="preserve">
368+
<value>Expected</value>
369+
</data>
370+
<data name="Failed" xml:space="preserve">
371+
<value>Failed</value>
372+
</data>
373+
<data name="FailedLowercase" xml:space="preserve">
374+
<value>failed</value>
375+
</data>
376+
<data name="FailedWithErrors" xml:space="preserve">
377+
<value>failed with {0} error(s)</value>
378+
</data>
379+
<data name="FailedWithErrorsAndWarnings" xml:space="preserve">
380+
<value>failed with {0} error(s) and {1} warning(s)</value>
381+
</data>
382+
<data name="FailedWithWarnings" xml:space="preserve">
383+
<value>failed with {0} warning(s)</value>
384+
</data>
385+
<data name="ForTest" xml:space="preserve">
386+
<value>For test</value>
387+
<comment>is followed by test name</comment>
388+
</data>
389+
<data name="FromFile" xml:space="preserve">
390+
<value>from</value>
391+
<comment>from followed by a file name to point to the file from which test is originating</comment>
392+
</data>
393+
<data name="InProcessArtifactsProduced" xml:space="preserve">
394+
<value>In process file artifacts produced:</value>
395+
</data>
396+
<data name="MinimumExpectedTestsPolicyViolation" xml:space="preserve">
397+
<value>Minimum expected tests policy violation, tests ran {0}, minimum expected {1}</value>
398+
<comment>{0}, {1} number of tests</comment>
399+
</data>
400+
<data name="OutOfProcessArtifactsProduced" xml:space="preserve">
401+
<value>Out of process file artifacts produced:</value>
402+
</data>
403+
<data name="Passed" xml:space="preserve">
404+
<value>Passed</value>
405+
</data>
406+
<data name="PassedLowercase" xml:space="preserve">
407+
<value>passed</value>
408+
</data>
409+
<data name="RunningTestsFrom" xml:space="preserve">
410+
<value>Running tests from</value>
411+
</data>
412+
<data name="SkippedLowercase" xml:space="preserve">
413+
<value>skipped</value>
414+
</data>
415+
<data name="StackFrameAt" xml:space="preserve">
416+
<value>at</value>
417+
<comment>at that is used for a stack frame location in a stack trace, is followed by a class and method name</comment>
418+
</data>
419+
<data name="StackFrameIn" xml:space="preserve">
420+
<value>in</value>
421+
<comment>in that is used in stack frame it is followed by file name</comment>
422+
</data>
423+
<data name="StandardError" xml:space="preserve">
424+
<value>Error output</value>
425+
</data>
426+
<data name="StandardOutput" xml:space="preserve">
427+
<value>Standard output</value>
428+
</data>
429+
<data name="TestDiscoverySummary" xml:space="preserve">
430+
<value>Discovered {0} tests in {1} assemblies.</value>
431+
<comment>0 is number of tests, 1 is count of assemblies</comment>
432+
</data>
433+
<data name="TestDiscoverySummarySingular" xml:space="preserve">
434+
<value>Discovered {0} tests.</value>
435+
<comment>0 is number of tests</comment>
436+
</data>
437+
<data name="TestRunSummary" xml:space="preserve">
438+
<value>Test run summary:</value>
439+
</data>
440+
<data name="ZeroTestsRan" xml:space="preserve">
441+
<value>Zero tests ran</value>
442+
</data>
335443
<data name="CmdUnsupportedTestRunnerDescription" xml:space="preserve">
336444
<value>Test runner not supported: {0}.</value>
337445
</data>

src/Cli/dotnet/commands/dotnet-test/Models.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ internal sealed record DiscoveredTest(string? Uid, string? DisplayName);
1313

1414
internal sealed record SuccessfulTestResult(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? StandardOutput, string? ErrorOutput, string? SessionUid);
1515

16-
internal sealed record FailedTestResult(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? StandardOutput, string? ErrorOutput, string? SessionUid);
16+
internal sealed record FailedTestResult(string? Uid, string? DisplayName, byte? State, long? Duration, string? Reason, FlatException[]? Exceptions, string? StandardOutput, string? ErrorOutput, string? SessionUid);
17+
18+
internal sealed record FlatException(string? ErrorMessage, string? ErrorType, string? StackTrace);
1719

1820
internal sealed record FileArtifact(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid);
1921

src/Cli/dotnet/commands/dotnet-test/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.DotNet.Cli
55
{
6-
internal record BuildConfigurationOptions(bool HasNoRestore, bool HasNoBuild, string Configuration, string Architecture);
6+
internal record BuildConfigurationOptions(bool HasNoRestore, bool HasNoBuild, bool HasListTests, string Configuration, string Architecture);
77

88
internal record BuildPathsOptions(string ProjectPath, string SolutionPath, string DirectoryPath);
99
}

0 commit comments

Comments
 (0)