Skip to content

Commit c53039b

Browse files
committed
Migrate from VSTest to Microsoft.Testing.Platform
1 parent c0413ac commit c53039b

File tree

23 files changed

+167
-258
lines changed

23 files changed

+167
-258
lines changed

.github/workflows/run-tests.yml

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,13 @@ jobs:
220220
TEST_LOG_PATH: ${{ github.workspace }}/artifacts/log/test-logs
221221
TestsRunningOutsideOfRepo: true
222222
run: >
223-
dotnet test -s .runsettings -v:n ${{ env.TEST_ASSEMBLY_NAME }}.dll
224-
-l "console;verbosity=normal"
225-
-l "trx;LogFilePrefix=${{ inputs.testShortName }}"
226-
-l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
227-
--blame
228-
--blame-hang-timeout ${{ inputs.testHangTimeout }}
229-
--blame-crash
223+
dotnet exec ${{ env.TEST_ASSEMBLY_NAME }}.dll
224+
@.runsettings
225+
--report-trx --report-trx-filename "${{ inputs.testShortName }}.trx"
226+
--hangdump --hangdump-timeout ${{ inputs.testHangTimeout }}
227+
--crashdump
230228
--results-directory ${{ github.workspace }}/testresults
231229
${{ inputs.extraTestArgs }}
232-
--
233-
RunConfiguration.CollectSourceInformation=true
234-
RunConfiguration.TestSessionTimeout=${{ inputs.testSessionTimeoutMs }}
235230
236231
- name: Run tests
237232
if: ${{ ! inputs.requiresNugets }}
@@ -240,24 +235,23 @@ jobs:
240235
CI: false
241236
DCP_DIAGNOSTICS_LOG_LEVEL: debug
242237
DCP_DIAGNOSTICS_LOG_FOLDER: ${{ github.workspace }}/testresults/dcp
238+
# During restore and build, we use -ci, which causes NUGET_PACKAGES to point to a local cache (Arcade behavior).
239+
# In this step, we are not using Arcade, but want to make sure that MSBuild is able to evaluate correctly.
240+
# So, we manually set NUGET_PACKAGES
241+
NUGET_PACKAGES: ${{ github.workspace }}/.packages
242+
243243
run: >
244244
${{ env.DOTNET_SCRIPT }} test ${{ env.TEST_PROJECT_PATH }}
245245
/p:ContinuousIntegrationBuild=true
246-
-s eng/testing/.runsettings
247-
-l "console;verbosity=normal"
248-
-l "trx;LogFilePrefix=${{ inputs.testShortName }}"
249-
-l "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
250-
"--blame"
251-
--blame-hang-timeout ${{ inputs.testHangTimeout }}
252-
--blame-crash
253-
--results-directory testresults
246+
-bl:${{ github.workspace }}/testresults/test.binlog
254247
--no-restore
255248
--no-build
256-
-bl:${{ github.workspace }}/testresults/test.binlog
257-
${{ inputs.extraTestArgs }}
258249
--
259-
RunConfiguration.CollectSourceInformation=true
260-
RunConfiguration.TestSessionTimeout=${{ inputs.testSessionTimeoutMs }}
250+
--report-trx --report-trx-filename "${{ inputs.testShortName }}.trx"
251+
--hangdump --hangdump-timeout ${{ inputs.testHangTimeout }}
252+
--crashdump
253+
--results-directory testresults
254+
${{ inputs.extraTestArgs }}
261255
262256
# Save the result of the previous steps - success or failure
263257
# in the form of a file result-success/result-failure -{name}.rst

.github/workflows/tests.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
with:
7575
testShortName: ${{ matrix.shortname }}
7676
os: "ubuntu-latest"
77-
extraTestArgs: "--filter \"(quarantined!=true)\""
77+
extraTestArgs: "--filter-not-trait \"quarantined=true\""
7878

7979
integrations_test_win:
8080
uses: ./.github/workflows/run-tests.yml
@@ -87,7 +87,7 @@ jobs:
8787
with:
8888
testShortName: ${{ matrix.shortname }}
8989
os: "windows-latest"
90-
extraTestArgs: "--filter \"(quarantined!=true)\""
90+
extraTestArgs: "--filter-not-trait \"quarantined=true\""
9191

9292
templates_test_lin:
9393
name: Templates Linux
@@ -102,8 +102,7 @@ jobs:
102102
testProjectPath: tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj
103103
testSessionTimeoutMs: 1200000
104104
testHangTimeout: 12m
105-
# append '.' to the name so only the test class with exactly that name is run
106-
extraTestArgs: "--filter \"(quarantined!=true)&(FullyQualifiedName~Aspire.Templates.Tests.${{ matrix.shortname }}.)\""
105+
extraTestArgs: "--filter-not-trait quarantined=true --filter-class Aspire.Templates.Tests.${{ matrix.shortname }}"
107106
requiresNugets: true
108107
requiresTestSdk: true
109108

@@ -120,8 +119,7 @@ jobs:
120119
testProjectPath: tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj
121120
testSessionTimeoutMs: 1200000
122121
testHangTimeout: 12m
123-
# append '.' to the name so only the test class with exactly that name is run
124-
extraTestArgs: "--filter \"(quarantined!=true)&(FullyQualifiedName~Aspire.Templates.Tests.${{ matrix.shortname }}.)\""
122+
extraTestArgs: "--filter-not-trait quarantined=true --filter-class Aspire.Templates.Tests.${{ matrix.shortname }}"
125123
requiresNugets: true
126124
requiresTestSdk: true
127125

Directory.Packages.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<AzureProvisiongVersion>1.0.0</AzureProvisiongVersion>
1111
<!-- The Npgsql version used when using Npgsql EF Core on net8. The major versions need to match between Npgsql and EF Core. -->
1212
<Npgsql8Version>8.0.6</Npgsql8Version>
13+
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
14+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
15+
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
1316
</PropertyGroup>
1417
<ItemGroup>
1518
<!-- Azure SDK for .NET dependencies -->
@@ -144,7 +147,6 @@
144147
<PackageVersion Include="Testcontainers.Oracle" Version="$(TestcontainersPackageVersion)" />
145148
<PackageVersion Include="Testcontainers.Elasticsearch" Version="$(TestcontainersPackageVersion)" />
146149
<PackageVersion Include="Testcontainers" Version="$(TestcontainersPackageVersion)" />
147-
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
148150
<!-- playground apps dependencies -->
149151
<PackageVersion Include="Microsoft.Orleans.Clustering.AzureStorage" Version="9.1.2" />
150152
<PackageVersion Include="Microsoft.Orleans.Persistence.AzureStorage" Version="9.1.2" />

eng/.runsettings

Lines changed: 0 additions & 33 deletions
This file was deleted.

eng/Testing.props

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
<Project>
2-
<PropertyGroup Condition="'$(UseVSTestRunner)' != 'true'">
3-
<_QuarantinedTestRunAdditionalArgs>-trait "quarantined=true"</_QuarantinedTestRunAdditionalArgs>
4-
<_NonQuarantinedTestRunAdditionalArgs>-notrait "quarantined=true"</_NonQuarantinedTestRunAdditionalArgs>
5-
</PropertyGroup>
6-
7-
<PropertyGroup Condition="'$(UseVSTestRunner)' == 'true'">
8-
<_QuarantinedTestRunAdditionalArgs>--filter "quarantined=true"</_QuarantinedTestRunAdditionalArgs>
9-
<_NonQuarantinedTestRunAdditionalArgs>--filter "quarantined!=true"</_NonQuarantinedTestRunAdditionalArgs>
2+
<PropertyGroup>
3+
<_QuarantinedTestRunAdditionalArgs>--filter-trait "quarantined=true"</_QuarantinedTestRunAdditionalArgs>
4+
<_NonQuarantinedTestRunAdditionalArgs>--filter-not-trait "quarantined=true"</_NonQuarantinedTestRunAdditionalArgs>
105
</PropertyGroup>
116

127
<PropertyGroup>
138
<BlameHangTimeout Condition="'$(BlameHangTimeout)' == ''">10m</BlameHangTimeout>
14-
<_BlameArgs>--blame --blame-hang-timeout $(BlameHangTimeout) --blame-crash</_BlameArgs>
9+
<_BlameArgs>--hangdump --hangdump-timeout $(BlameHangTimeout) --crash-dump</_BlameArgs>
1510

1611
<TestRunnerAdditionalArguments Condition="'$(RunQuarantinedTests)' == ''">$(TestRunnerAdditionalArguments) $(_NonQuarantinedTestRunAdditionalArgs) $(TestRunnerAdditionalArguments) $(_BlameArgs)</TestRunnerAdditionalArguments>
1712
<TestRunnerAdditionalArguments Condition="'$(RunQuarantinedTests)' == 'true'">$(TestRunnerAdditionalArguments) $(_QuarantinedTestRunAdditionalArgs) $(TestRunnerAdditionalArguments) $(_BlameArgs)</TestRunnerAdditionalArguments>

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<DotNetRuntimePreviousVersionForTesting>8.0.13</DotNetRuntimePreviousVersionForTesting>
1313
<!-- dotnet 8.0 versions for running tests - used for templates tests -->
1414
<DotNetSdkPreviousVersionForTesting>8.0.406</DotNetSdkPreviousVersionForTesting>
15-
<UseVSTestRunner>true</UseVSTestRunner>
1615
<XunitV3Version>2.0.0</XunitV3Version>
1716
<XUnitAnalyzersVersion>1.20.0</XUnitAnalyzersVersion>
1817
<XunitRunnerVisualStudioVersion>3.0.2</XunitRunnerVisualStudioVersion>
18+
<MicrosoftTestingPlatformVersion>1.6.3</MicrosoftTestingPlatformVersion>
1919
<!-- Enable to remove prerelease label. -->
2020
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">false</StabilizePackageVersion>
2121
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
2+
<Project>
3+
4+
<Target Name="RunTests"
5+
Outputs="%(TestToRun.ResultsStdOutPath)"
6+
Condition="'@(TestToRun)' != ''">
7+
<Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Test" />
8+
9+
<PropertyGroup>
10+
<_TestResultDirectory>$([System.IO.Path]::GetDirectoryName('%(TestToRun.ResultsTrxPath)'))</_TestResultDirectory>
11+
<_TestResultTrxFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsTrxPath)'))</_TestResultTrxFileName>
12+
<_TestResultXmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsXmlFileName)'))</_TestResultXmlFileName>
13+
<_TestResultHtmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsHtmlFileName)'))</_TestResultHtmlFileName>
14+
</PropertyGroup>
15+
16+
<PropertyGroup>
17+
<_TestEnvironment>%(TestToRun.EnvironmentDisplay)</_TestEnvironment>
18+
<_TestAssembly>%(TestToRun.Identity)</_TestAssembly>
19+
<_TestAssembly>$([System.IO.Path]::ChangeExtension($(_TestAssembly), '.exe'))</_TestAssembly>
20+
<_TestRuntime>%(TestToRun.TestRuntime)</_TestRuntime>
21+
<_TestTimeout>%(TestToRun.TestTimeout)</_TestTimeout>
22+
<_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments>
23+
24+
<_TestRunner>$(_TestAssembly)</_TestRunner>
25+
<_TestRunnerArgs>$(_TestRunnerAdditionalArguments) --results-directory "$(_TestResultDirectory)" --report-xunit --report-xunit-filename "$(_TestResultXmlFileName)" --report-xunit-html --report-xunit-html-filename "$(_TestResultHtmlFileName)"</_TestRunnerArgs>
26+
</PropertyGroup>
27+
28+
<PropertyGroup Condition="'$(_TestRuntime)' == 'Core'">
29+
<_TestRunnerArgs>$(_TestRunnerArgs) --auto-reporters off</_TestRunnerArgs>
30+
</PropertyGroup>
31+
32+
<PropertyGroup>
33+
<_TestRunnerCommand>"$(_TestRunner)" $(_TestRunnerArgs)</_TestRunnerCommand>
34+
35+
<!--
36+
Redirect std output of the runner.
37+
Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name)
38+
-->
39+
<_TestRunnerCommand Condition="'$(TestCaptureOutput)' != 'false'">$(_TestRunnerCommand) > "%(TestToRun.ResultsStdOutPath)" 2>&amp;1</_TestRunnerCommand>
40+
</PropertyGroup>
41+
42+
<ItemGroup>
43+
<_OutputFiles Include="%(TestToRun.ResultsXmlPath)" />
44+
<_OutputFiles Include="%(TestToRun.ResultsHtmlPath)" />
45+
<_OutputFiles Include="%(TestToRun.ResultsStdOutPath)" />
46+
</ItemGroup>
47+
48+
<MakeDir Directories="@(_OutputFiles->'%(RootDir)%(Directory)')"/>
49+
<Delete Files="@(_OutputFiles)" />
50+
51+
<Message Text="Running tests: $(_TestAssembly) [$(_TestEnvironment)]" Importance="high"/>
52+
<Exec Command='$(_TestRunnerCommand)'
53+
LogStandardErrorAsError="false"
54+
WorkingDirectory="$(_TargetDir)"
55+
IgnoreExitCode="true"
56+
Timeout="$(_TestTimeout)"
57+
EnvironmentVariables="DOTNET_ROOT=$(DotNetRoot);DOTNET_ROOT_X86=$(DotNetRoot)x86"
58+
ContinueOnError="WarnAndContinue">
59+
<Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" />
60+
</Exec>
61+
62+
<!--
63+
Add command line to the log.
64+
-->
65+
<WriteLinesToFile File="%(TestToRun.ResultsStdOutPath)"
66+
Overwrite="false"
67+
Lines=";=== COMMAND LINE ===;$(_TestRunnerCommand)"
68+
Condition="'$(TestCaptureOutput)' != 'false'" />
69+
70+
<!--
71+
Report test status.
72+
-->
73+
<Message Text="Tests succeeded: $(_TestAssembly) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" />
74+
75+
<PropertyGroup>
76+
<_ResultsFileToDisplay>%(TestToRun.ResultsHtmlPath)</_ResultsFileToDisplay>
77+
<_ResultsFileToDisplay Condition="!Exists('$(_ResultsFileToDisplay)')">%(TestToRun.ResultsStdOutPath)</_ResultsFileToDisplay>
78+
</PropertyGroup>
79+
80+
<!--
81+
Ideally we would set ContinueOnError="ErrorAndContinue" so that when a test fails in multi-targeted test project
82+
we'll still run tests for all target frameworks. ErrorAndContinue doesn't work well on Linux though: https://github.com/Microsoft/msbuild/issues/3961.
83+
-->
84+
<Error Text="Tests failed: $(_ResultsFileToDisplay) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0' and '$(_ErrorOnTestFailure)' != 'false'" File="XUnit" />
85+
86+
<ItemGroup>
87+
<FileWrites Include="@(_OutputFiles)"/>
88+
</ItemGroup>
89+
</Target>
90+
91+
</Project>

eng/Xunit3/Xunit3.targets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
<PackageVersion Include="xunit.v3.core" Version="$(XunitV3Version)" />
55
<PackageVersion Include="xunit.analyzers" Version="$(XunitAnalyzersVersion)" />
66
<PackageVersion Include="xunit.v3.assert" Version="$(XunitV3Version)" />
7-
<PackageVersion Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
87
<PackageVersion Include="xunit.v3.runner.console" Version="$(XunitV3Version)" />
8+
<PackageVersion Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
9+
<PackageVersion Include="Microsoft.Testing.Platform.MSBuild" Version="$(MicrosoftTestingPlatformVersion)" />
10+
<PackageVersion Include="Microsoft.Testing.Extensions.HangDump" Version="$(MicrosoftTestingPlatformVersion)" />
11+
<PackageVersion Include="Microsoft.Testing.Extensions.CrashDump" Version="$(MicrosoftTestingPlatformVersion)" />
12+
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />
913

1014
<PackageReference Include="xunit.v3" />
1115
<PackageReference Include="xunit.v3.core" />
1216
<PackageReference Include="xunit.analyzers" />
1317
<PackageReference Include="xunit.v3.assert" />
14-
<PackageReference Include="xunit.runner.visualstudio" />
18+
<PackageReference Include="Microsoft.Testing.Platform" />
19+
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" />
20+
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" />
21+
<PackageReference Include="Microsoft.Testing.Extensions.CrashDump" />
22+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
1523
</ItemGroup>
1624

17-
<Import Project="..\tools\VSTest.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
18-
</Project>
25+
<Import Project="Microsoft.Testing.Platform.targets" />
26+
</Project>

eng/testing/.runsettings

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,2 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<RunSettings>
3-
<RunConfiguration>
4-
<!-- Timeout in ms, 20 minutes -->
5-
<TestSessionTimeout>1200000</TestSessionTimeout>
6-
<!-- Filter out failing (wrong framework, platform, runtime or activeissue) tests -->
7-
<TestCaseFilter>category!=failing</TestCaseFilter>
8-
</RunConfiguration>
9-
<LoggerRunSettings>
10-
<Loggers>
11-
<Logger friendlyName="trx">
12-
<Configuration>
13-
<LogFileName>TestResults.trx</LogFileName>
14-
</Configuration>
15-
</Logger>
16-
<Logger friendlyName="console">
17-
<Configuration>
18-
<Verbosity>normal</Verbosity>
19-
</Configuration>
20-
</Logger>
21-
<Logger friendlyName="blame" enabled="True" />
22-
</Loggers>
23-
</LoggerRunSettings>
24-
<DataCollectionRunSettings>
25-
<DataCollectors>
26-
<!-- Enables blame -->
27-
<DataCollector friendlyName="blame" enabled="True">
28-
<Configuration>
29-
<CollectDump DumpType="Full" />
30-
<CollectDumpOnTestSessionHang TestTimeout="7min" HangDumpType="Full" />
31-
</Configuration>
32-
</DataCollector>
33-
</DataCollectors>
34-
</DataCollectionRunSettings>
35-
</RunSettings>
1+
# Filter out failing (wrong framework, platform, runtime or activeissue) tests
2+
--filter-not-trait "category=failing"

tests/Aspire.Components.Common.Tests/Aspire.Components.Common.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
5+
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --ignore-exit-code 8</TestingPlatformCommandLineArguments>
56
</PropertyGroup>
67

78
<ItemGroup>

0 commit comments

Comments
 (0)