-
Notifications
You must be signed in to change notification settings - Fork 382
Support XUnitV3 as test runner #15671
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
87cfd96
Support XUnitV3 as test runner
Youssef1313 0662ba6
Progress
Youssef1313 31a5f2f
Remove xunit.v3.runner.console
Youssef1313 22cae6c
Default to MTP for xunit.v3
Youssef1313 3a460bc
Few fixes
Youssef1313 53e0b37
Remove v3 runner
Youssef1313 81cc9c3
Error when mixing MTP and VSTest
Youssef1313 6ba9ccb
Add DependsOnTargets
Youssef1313 e865bc0
Adjust
Youssef1313 a7cb8b3
Fix typos
Youssef1313 e4376bf
Trx
Youssef1313 1958615
Address review comment
Youssef1313 ff4f695
Move to beginning
Youssef1313 41b6bca
Set XUnitCoreSettingsFile as well
Youssef1313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> | ||
<Project> | ||
|
||
<Target Name="RunTests" | ||
Outputs="%(TestToRun.ResultsStdOutPath)" | ||
Condition="'@(TestToRun)' != ''"> | ||
<Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Test" /> | ||
|
||
<PropertyGroup Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'"> | ||
<_TestResultDirectory>$([System.IO.Path]::GetDirectoryName('%(TestToRun.ResultsTrxPath)'))</_TestResultDirectory> | ||
<_TestResultTrxFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsTrxPath)'))</_TestResultTrxFileName> | ||
<_TestResultXmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsXmlPath)'))</_TestResultXmlFileName> | ||
<_TestResultHtmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsHtmlPath)'))</_TestResultHtmlFileName> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<_TestEnvironment>%(TestToRun.EnvironmentDisplay)</_TestEnvironment> | ||
<_TestAssembly>%(TestToRun.Identity)</_TestAssembly> | ||
<_TestRuntime>%(TestToRun.TestRuntime)</_TestRuntime> | ||
<_TestTimeout>%(TestToRun.TestTimeout)</_TestTimeout> | ||
<_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments> | ||
|
||
<_TestRunner>%(TestToRun.RunCommand)</_TestRunner> | ||
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' != 'true'">%(TestToRun.RunArguments) $(_TestRunnerAdditionalArguments) -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" -trx "%(TestToRun.ResultsTrxPath)"</_TestRunnerArgs> | ||
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'">%(TestToRun.RunArguments) $(_TestRunnerAdditionalArguments) --results-directory "$(_TestResultDirectory)" --report-xunit --report-xunit-filename "$(_TestResultXmlFileName)" --report-xunit-html --report-xunit-html-filename "$(_TestResultHtmlFileName)" --report-trx --report-trx-filename "$(_TestResultTrxFileName)"</_TestRunnerArgs> | ||
|
||
<TestDotNetRoot Condition="'$(TestDotNetRoot)' == ''">$(DotNetRoot)</TestDotNetRoot> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(_TestRuntime)' == 'Core'"> | ||
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' != 'true'">$(_TestRunnerArgs) -noAutoReporters</_TestRunnerArgs> | ||
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'">$(_TestRunnerArgs) --auto-reporters off</_TestRunnerArgs> | ||
</PropertyGroup> | ||
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm using the same |
||
|
||
<PropertyGroup> | ||
<_TestRunnerCommand>"$(_TestRunner)" $(_TestRunnerArgs)</_TestRunnerCommand> | ||
|
||
<!-- | ||
Redirect std output of the runner. | ||
Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name) | ||
--> | ||
<_TestRunnerCommand Condition="'$(TestCaptureOutput)' != 'false'">$(_TestRunnerCommand) >> "%(TestToRun.ResultsStdOutPath)" 2>&1</_TestRunnerCommand> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<_OutputFiles Include="%(TestToRun.ResultsXmlPath)" /> | ||
<_OutputFiles Include="%(TestToRun.ResultsHtmlPath)" /> | ||
<_OutputFiles Include="%(TestToRun.ResultsStdOutPath)" /> | ||
</ItemGroup> | ||
|
||
<MakeDir Directories="@(_OutputFiles->'%(RootDir)%(Directory)')"/> | ||
<Delete Files="@(_OutputFiles)" /> | ||
|
||
<Message Text="Running tests: $(_TestAssembly) [$(_TestEnvironment)]" Importance="high"/> | ||
|
||
<!-- | ||
Add command line to the log. | ||
--> | ||
<Exec Command="echo === COMMAND LINE === > %(TestToRun.ResultsStdOutPath) | ||
echo $(_TestRunnerCommand) >> %(TestToRun.ResultsStdOutPath)" /> | ||
|
||
<Exec Command='$(_TestRunnerCommand)' | ||
LogStandardErrorAsError="false" | ||
WorkingDirectory="$(_TargetDir)" | ||
IgnoreExitCode="true" | ||
Timeout="$(_TestTimeout)" | ||
EnvironmentVariables="DOTNET_ROOT=$(TestDotNetRoot);DOTNET_ROOT_X86=$(TestDotNetRoot)x86" | ||
ContinueOnError="WarnAndContinue"> | ||
<Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" /> | ||
</Exec> | ||
|
||
<!-- | ||
Report test status. | ||
--> | ||
<Message Text="Tests succeeded: $(_TestAssembly) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" /> | ||
|
||
<PropertyGroup> | ||
<_ResultsFileToDisplay>%(TestToRun.ResultsHtmlPath)</_ResultsFileToDisplay> | ||
<_ResultsFileToDisplay Condition="!Exists('$(_ResultsFileToDisplay)')">%(TestToRun.ResultsStdOutPath)</_ResultsFileToDisplay> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Ideally we would set ContinueOnError="ErrorAndContinue" so that when a test fails in multi-targeted test project | ||
we'll still run tests for all target frameworks. ErrorAndContinue doesn't work well on Linux though: https://github.com/Microsoft/msbuild/issues/3961. | ||
--> | ||
<Error Text="Tests failed: $(_ResultsFileToDisplay) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0' and '$(_ErrorOnTestFailure)' != 'false'" File="XUnit" /> | ||
|
||
<ItemGroup> | ||
<FileWrites Include="@(_OutputFiles)"/> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
47 changes: 47 additions & 0 deletions
47
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<UseVSTestRunner Condition="'$(UseVSTestRunner)' != 'true'">false</UseVSTestRunner> | ||
|
||
<!-- Default to using MTP --> | ||
<UseMicrosoftTestingPlatformRunner Condition="'$(UseMicrosoftTestingPlatformRunner)' == ''">true</UseMicrosoftTestingPlatformRunner> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="xunit.v3" Version="$(XUnitV3Version)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" /> | ||
<!-- TODO --> | ||
<!-- <PackageReference Include="Microsoft.DotNet.XUnitV3Assert" Version="$(MicrosoftDotNetXUnitAssertVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(UseDotNetXUnitAssert)' == 'true' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> --> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'"> | ||
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" /> | ||
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="$(MicrosoftTestingPlatformVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" /> | ||
<PackageReference Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<XUnitDesktopSettingsFile Condition="'$(XUnitDesktopSettingsFile)' == ''">$(MSBuildThisFileDirectory)xunit.runner.json</XUnitDesktopSettingsFile> | ||
Youssef1313 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<XUnitCoreSettingsFile Condition="'$(XUnitCoreSettingsFile)' == ''">$(MSBuildThisFileDirectory)xunit.runner.json</XUnitCoreSettingsFile> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Include settings file (xunit.runner.json) if specified. | ||
--> | ||
<ItemGroup> | ||
<None Include="$(XUnitDesktopSettingsFile)" | ||
CopyToOutputDirectory="PreserveNewest" | ||
Visible="false" | ||
Condition="'$(XUnitDesktopSettingsFile)' != '' and '$(TargetFrameworkIdentifier)' == '.NETFramework'" /> | ||
|
||
<None Include="$(XUnitCoreSettingsFile)" | ||
CopyToOutputDirectory="PreserveNewest" | ||
Visible="false" | ||
Condition="'$(XUnitCoreSettingsFile)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> | ||
</ItemGroup> | ||
|
||
<Import Project="XUnitV3.Runner.targets" Condition="!$(UseVSTestRunner)"/> | ||
ViktorHofer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Import Project="..\VSTest.targets" Condition="$(UseVSTestRunner)"/> | ||
|
||
</Project> |
4 changes: 4 additions & 0 deletions
4
src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/xunit.runner.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", | ||
"shadowCopy": false | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically breaking.
If a repo is setting
EnableMSTestRunner
,EnableNUnitRunner
, orUseMicrosoftTestingPlatformRunner
but is not either opting-in viadotnet.config
orTestingPlatformCommandLineArguments
, then their setup will actually be using VSTest when invokingdotnet test
directly.This also means that such repos are not properly configured to use MTP, where the intent may be to use it. So I think it may be reasonable to break, but I'll let you decide.