Skip to content

Run VSTest tests with MTP #15079

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

Merged
merged 23 commits into from
Jul 4, 2025
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
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ stages:
-nobl
-integrationTest
-performanceTest
/bl:$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)/Test.binlog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this below the -nobl or the otherway around

name: Test
displayName: Test

Expand Down
2 changes: 2 additions & 0 deletions dotnet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[dotnet.test.runner]
name = "Microsoft.Testing.Platform"
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<PropertyGroup Label="VSTest test settings">
<!-- Name of the elements must be in sync with test\Microsoft.TestPlatform.TestUtilities\IntegrationTestBase.cs -->
<AwesomeAssertionsVersion>8.1.0</AwesomeAssertionsVersion>
<MicrosoftTestingPlatformVersion>1.7.2</MicrosoftTestingPlatformVersion>
<MoqVersion>4.16.1</MoqVersion>
<!-- For coverage use our own package on latest stable -->
<MicrosoftCodeCoverageVersion>17.9.0</MicrosoftCodeCoverageVersion>
Expand Down
10 changes: 6 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.301",
"version": "10.0.100-preview.5.25269.23",
"rollForward": "minor",
"allowPrerelease": false,
"architecture": "x64"
Expand All @@ -13,22 +13,24 @@
"5.0.17",
"6.0.32",
"7.0.20",
"8.0.7"
"8.0.7",
"9.0.5"
],
"dotnet/x86": [
"2.1.30",
"3.1.32",
"5.0.17",
"6.0.32",
"7.0.20",
"8.0.7"
"8.0.7",
"9.0.5"
]
},
"vs": {
"version": "17.8.0"
},
"vswhere": "2.2.7",
"dotnet": "9.0.301"
"dotnet": "10.0.100-preview.5.25269.23"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.25325.4"
Expand Down
12 changes: 10 additions & 2 deletions playground/TestPlatform.Playground/TestPlatform.Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<!-- MSB3276 Suppress warnings about conflicts between different versions of the same dependent assembly -->
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3276</MSBuildWarningsAsMessages>

<EnableMSTestRunner>false</EnableMSTestRunner>
<!--
Arcade uses UseMSTestRunner instead of EnableMSTestRunner
https://github.com/dotnet/arcade/blob/c9ed073c0a2a828aed8f5c6ecb0a544b0f0fd3f8/src/Microsoft.DotNet.Arcade.Sdk/tools/MSTest/MSTest.targets#L29
https://github.com/dotnet/arcade/issues/15875
-->
<UseMSTestRunner>false</UseMSTestRunner>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -12,8 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.9.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.9.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<IsTestProject>true</IsTestProject>
<!-- We build this only for net48, and it fails to skip this on Linux in Aracade otherwise. -->
<IsTestProject Condition=" '$(OS)' != 'Windows_NT' ">false</IsTestProject>
<OutputType Condition=" '$(OS)' == 'Windows_NT' ">Exe</OutputType>
</PropertyGroup>

<PropertyGroup Label="Configuration">
Expand Down
11 changes: 11 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@

<PropertyGroup>
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
<EnableMSTestRunner>true</EnableMSTestRunner>
<!--
Arcade uses UseMSTestRunner instead of EnableMSTestRunner
https://github.com/dotnet/arcade/blob/c9ed073c0a2a828aed8f5c6ecb0a544b0f0fd3f8/src/Microsoft.DotNet.Arcade.Sdk/tools/MSTest/MSTest.targets#L29
https://github.com/dotnet/arcade/issues/15875
-->
<UseMSTestRunner>true</UseMSTestRunner>
</PropertyGroup>

<ItemGroup>
<PackageReference Condition="'$(IsTestProject)'=='true' AND '$(EnableMSTestRunner)'=='true'" Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.IO;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -24,7 +25,7 @@ public void MSBuildLoggerCanBeEnabledByBuildPropertyAndDoesNotEatSpecialChars(Ru

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
// Forcing terminal logger so we can see the output when it is redirected
InvokeDotnetTest($@"{projectPath} -tl:on -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}");
InvokeDotnetTest($@"{projectPath} -tl:on -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));

// The output:
// Determining projects to restore...
Expand Down Expand Up @@ -53,7 +54,7 @@ public void MSBuildLoggerCanBeDisabledByBuildProperty(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:VsTestUseMSBuildOutput=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}");
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:VsTestUseMSBuildOutput=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));

// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
Expand All @@ -73,7 +74,7 @@ public void MSBuildLoggerCanBeDisabledByEnvironmentVariableProperty(RunnerInfo r
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", environmentVariables: new Dictionary<string, string?> { ["MSBUILDENSURESTDOUTFORTASKPROCESSES"] = "1" });
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", environmentVariables: new Dictionary<string, string?> { ["MSBUILDENSURESTDOUTFORTASKPROCESSES"] = "1" }, workingDirectory: Path.GetDirectoryName(projectPath));

// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void RunDotnetTestWithCsproj(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("SimpleTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}");
InvokeDotnetTest($@"{projectPath} -p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));

// ensure our dev version is used
StdOutputContains(GetFinalVersion(IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion));
Expand All @@ -43,7 +43,7 @@ public void RunDotnetTestWithDll(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("SimpleTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal""");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(assemblyPath));

// ensure our dev version is used
StdOutputContains(GetFinalVersion(IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion));
Expand All @@ -60,7 +60,7 @@ public void RunDotnetTestWithCsprojPassInlineSettings(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("ParametrizedTestProject.csproj");
InvokeDotnetTest($@"{projectPath} --logger:""Console;Verbosity=normal"" -p:VSTestUseMSBuildOutput=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion} -- TestRunParameters.Parameter(name =\""weburl\"", value=\""http://localhost//def\"")");
InvokeDotnetTest($@"{projectPath} --logger:""Console;Verbosity=normal"" -p:VSTestUseMSBuildOutput=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion} -- TestRunParameters.Parameter(name =\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(projectPath));

ValidateSummaryStatus(1, 0, 0);
ExitCodeEquals(0);
Expand All @@ -75,7 +75,7 @@ public void RunDotnetTestWithDllPassInlineSettings(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("ParametrizedTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" -- TestRunParameters.Parameter(name=\""weburl\"", value=\""http://localhost//def\"")");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" -- TestRunParameters.Parameter(name=\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(assemblyPath));

ValidateSummaryStatus(1, 0, 0);
ExitCodeEquals(0);
Expand All @@ -93,7 +93,7 @@ public void RunDotnetTestWithNativeDll(RunnerInfo runnerInfo)
string assemblyRelativePath = @"microsoft.testplatform.testasset.nativecpp\2.0.0\contentFiles\any\any\x64\Microsoft.TestPlatform.TestAsset.NativeCPP.dll";
var assemblyAbsolutePath = Path.Combine(_testEnvironment.PackageDirectory, assemblyRelativePath);

InvokeDotnetTest($@"{assemblyAbsolutePath} --logger:""Console;Verbosity=normal"" --diag:c:\temp\logscpp\");
InvokeDotnetTest($@"{assemblyAbsolutePath} --logger:""Console;Verbosity=normal"" --diag:c:\temp\logscpp\", workingDirectory: Path.GetDirectoryName(assemblyAbsolutePath));

ValidateSummaryStatus(1, 1, 0);
ExitCodeEquals(1);
Expand All @@ -108,7 +108,7 @@ public void RunDotnetTestAndSeeOutputFromConsoleWriteLine(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("OutputtingTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" ");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" ", workingDirectory: Path.GetDirectoryName(assemblyPath));

StdOutputContains("MY OUTPUT FROM TEST");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<PropertyGroup>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
13 changes: 0 additions & 13 deletions test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,15 @@ public void RunSettingsAreLoadedFromProject(RunnerInfo runnerInfo)

var projectName = "ProjectFileRunSettingsTestProject.csproj";
var projectPath = GetIsolatedTestAsset(projectName);
InvokeDotnetTest($@"{projectPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}");
InvokeDotnetTest($@"{projectPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
ValidateSummaryStatus(0, 1, 0);

// make sure that we can revert the project settings back by providing a config from command line
// keeping this in the same test, because it is easier to see that we are reverting settings that
// are honored by dotnet test, instead of just using the default, which would produce the same
// result
var settingsPath = GetProjectAssetFullPath(projectName, "inconclusive.runsettings");
InvokeDotnetTest($@"{projectPath} --settings {settingsPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}");
InvokeDotnetTest($@"{projectPath} --settings {settingsPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
ValidateSummaryStatus(0, 0, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.AdapterUtilities.UnitTests</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);RS1024</NoWarn>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.Build.UnitTests</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions test/Microsoft.TestPlatform.Build.UnitTests/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.Client.UnitTests</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions test/Microsoft.TestPlatform.Client.UnitTests/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.Common.UnitTests</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions test/Microsoft.TestPlatform.Common.UnitTests/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.CommunicationUtilities.PlatformTests</AssemblyName>
</PropertyGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.CommunicationUtilities.UnitTests</AssemblyName>
</PropertyGroup>
<ItemGroup Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetFrameworkMinimum)'))">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFrameworks>net9.0;net48</TargetFrameworks>
<OutputType Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppMinimum)')) ">Exe</OutputType>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.TestPlatform.CoreUtilities.UnitTests</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
14 changes: 0 additions & 14 deletions test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Program.cs

This file was deleted.

Loading
Loading