Skip to content

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Apr 2, 2025

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #8293

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 2, 2025
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/migrate-to-mtp branch 17 times, most recently from 35c30c1 to c53039b Compare April 2, 2025 15:30
@Youssef1313 Youssef1313 force-pushed the dev/ygerges/migrate-to-mtp branch from c53039b to e427f13 Compare April 2, 2025 15:42
@danmoseley danmoseley added area-engineering-systems infrastructure helix infra engineering repo stuff and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 2, 2025
</Loggers>
</LoggerRunSettings>
</RunSettings>
--show-live-output on
Copy link
Member

Choose a reason for hiding this comment

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

if we wanted to experiment with parallel tests runs for a particular library, we'd put it in a file like this presumably? (right now none may be stable for parallel runs, nor diagnosable, but for traditional unit tests it may be possible)

Copy link
Member Author

Choose a reason for hiding this comment

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

Either that, or add it to TestingPlatformCommandLineArguments.

Note: the current file is no longer really runsettings, it's a response file. RunSettings is actually not supported by core MTP (there is limited support for it through VSTestBridge, but xUnit doesn't use the bridge).

Copy link
Member Author

Choose a reason for hiding this comment

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

You can also do dotnet run --project path/to/test-project.csproj -- --help and it will show you all the command-line options available.

Copy link
Member

Choose a reason for hiding this comment

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

why do we still have .runsettings if it's not really supported?

Copy link
Member Author

@Youssef1313 Youssef1313 Apr 2, 2025

Choose a reason for hiding this comment

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

The file name is just .runsettings but it acts as a command-line response file. I can rename for clarity.

The original intent is very unclear to me, there are too many .runsettings scattered and it's not claer which is used for what and when.

If you can clarify the original intent, maybe there can be a good room to clean it up more.

Copy link
Member

Choose a reason for hiding this comment

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

I cannot clarify. Possibly @radical can or perhaps it's just happenstance, this isn't a mature repo. Any cleanup welcome!

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I went ahead and cleaned up all the .runsettings.

Any customizations that are needed for a specific project can be done via TestingPlatformCommandLineArguments MSBuild property. This allows more flexibility as you can customize in Directory.Build.[props|targets] as well, based on any conditions. Previously, only one .runsettings file can be passed, and it was too hard to track which runsettings is used where.

Copy link
Member

Choose a reason for hiding this comment

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

We have various runsettings to have different logging and timeout setup, and the files themselves weren't compostable. This was useful for local vs CI runs. I did start moving to overriding on the command line. But cleaning all this up to use command line parameters via msbuild properties will be great!!

RussKie added a commit that referenced this pull request Apr 10, 2025
1. Take build agent OS in account when running tests
Addresses #8498 (comment)

2. Read trx from correct location
Resolves #8683
@RussKie RussKie mentioned this pull request Apr 10, 2025
@Youssef1313
Copy link
Member Author

Youssef1313 commented Apr 10, 2025

@RussKie Why is the placement of this mattering? Are you parsing the log file programmatically somewhere?

The discrepancy mostly comes from Arcade. With VSTest, the command line comes before the test execution:

https://github.com/dotnet/arcade/blob/03b4b258fc72e5663f2ad701df5d70129aa2df8a/src/Microsoft.DotNet.Arcade.Sdk/tools/VSTest.targets#L44-L58

For xunit.v2 runner, it comes after:

https://github.com/dotnet/arcade/blob/03b4b258fc72e5663f2ad701df5d70129aa2df8a/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnit/XUnit.Runner.targets#L69-L84

For xunit.v3:

@RussKie
Copy link
Contributor

RussKie commented Apr 10, 2025

Some logs can be very log (hundreds and thousands of lines long), and having the command line at the end hinders the process.

@RussKie
Copy link
Contributor

RussKie commented Apr 10, 2025

I didn't realise the VSTest and XUnit had different implementations 😲

<!-- https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-exit-codes -->
<!-- Exit code 8 is "zero tests ran" -->
<!-- Currently, none of the tests in this project run in CI. All are ignored -->
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --ignore-exit-code 8</TestingPlatformCommandLineArguments>
Copy link
Contributor

Choose a reason for hiding this comment

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

@Youssef1313 this doesn't appear to be used in Microsoft.Testing.Platform.targets, which results in the tests to fail
image

Should this be tucked on to _TestRunnerArgs?

<_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments>
<_TestRunner>$(_TestAssembly)</_TestRunner>
<_TestRunnerArgs>$(_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>
</PropertyGroup>
<PropertyGroup Condition="'$(_TestRuntime)' == 'Core'">
<_TestRunnerArgs>$(_TestRunnerArgs) --auto-reporters off</_TestRunnerArgs>
</PropertyGroup>

Copy link
Member Author

Choose a reason for hiding this comment

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

@RussKie TestingPlatformCommandLineArguments is currently used when invoking dotnet test but not when invoked via Arcade.

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the right way to fix this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you can simply append TestingPlatformCommandLineArguments to _TestRunnerArgs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, what I'm suggesting won't probably be possible without my PR on Arcade side. For now I think you could duplicate the --ignore-exit-code 8 on both sides.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or simply just rename Aspire.Components.Common.Tests to end with TestUtilities if it's really not intended to be a test project, then you don't need the --ignore-exit-code 8 at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or simply just rename Aspire.Components.Common.Tests to end with TestUtilities if it's really not intended to be a test project, then you don't need the --ignore-exit-code 8 at all.

Yep, working on it

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can do it easily (if at all).
The project uses XUnit API (like fact and theory), and we need to import the Xunit assemblies. Those are defined in eng/Xunit3/Xunit3.targets and can only be imported by test projects. If the targets imported explicitly, then the build gets failed by _XunitValidateBuild declared in xunit.v3.core.targets

D:\Development\dotnet-aspire\.packages\xunit.v3.core\2.0.0\buildTransitive\xunit.v3.core.targets(15,5): xUnit.net v3 test projects must be executable (set project property '<OutputType>Exe</OutputType>'). If this is not a test project, reference xunit.v3.extensibilty.core instead. [D:\Development\dotnet-aspire\tests\Aspire.Components.Common.Tests\Aspire.Components.Common.TestUtilities.csproj]

Copy link
Member Author

@Youssef1313 Youssef1313 Apr 10, 2025

Choose a reason for hiding this comment

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

@RussKie You need to reference only xunit.v3.extensibility.core in that project, and not xunit.v3.core, nor xunit.v3

RussKie added a commit that referenced this pull request Apr 10, 2025
1. Take build agent OS in account when running tests
Addresses #8498 (comment)

2. Read trx from correct location
Resolves #8683
RussKie added a commit that referenced this pull request Apr 10, 2025
1. Take build agent OS in account when running tests
Addresses #8498 (comment)

2. Read trx from correct location
Resolves #8683
RussKie added a commit that referenced this pull request Apr 10, 2025
1. Take build agent OS in account when running tests
Addresses #8498 (comment)

2. Read trx from correct location
Resolves #8683
@captainsafia
Copy link
Member

Have we validated that these changes work with the Test Explorer in VS Code?

I've ran into a few issues debugging in the repo (see microsoft/vscode-dotnettools#1923 and microsoft/vscode-dotnettools#1922) since this change went in. Test discovery and execution appear to behave much more reliably in VS Code if I revert the commit associated with this PR.

Does anyone have any insights on the state of Microsoft.Testing.Platform support on VS Code?

@Youssef1313
Copy link
Member Author

@captainsafia It's expected to work in VS Code if you are using DevKit

@Youssef1313
Copy link
Member Author

@captainsafia I don't know if the option is enabled by default or not, but you need to make sure this is turned on:

image

(we did a change to no longer mark it "experimental" but not sure if the change has already shipped or not)

@captainsafia
Copy link
Member

@Youssef1313 Yep, I'm on a release of the extension without the experimental flag and have the feature enabled. I'm running into issues with debugging tests and lack of reliability with the test discovery.

image

Is there an SDK requirement associated with this change?

@Youssef1313
Copy link
Member Author

There shouldn't be SDK requirement associated. From your logs:

No test is available in /Users/captainsafia/git/aspire/acr-resource/artifacts/bin/Aspire.Oracle.EntityFrameworkCore.Tests/Debug/net8.0/Aspire.Oracle.EntityFrameworkCore.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

It seems like VS Code is treating the project as VSTest and not MTP. @drognanar would be the right contact.

@mitchdenny
Copy link
Member

Looks like this could have broken me as well (I'm trying to use Codespaces as my primary environment).

@Youssef1313
Copy link
Member Author

@captainsafia @mitchdenny As a potential temporary workaround, could you try adding a PackageReference to xunit.runner.visualstudio (version 3.0.2)?

This would go in:

and version would be defined in:

<PropertyGroup>

@mitchdenny
Copy link
Member

Happy to give it a shot. Can you explain why this might fix it?

@Youssef1313
Copy link
Member Author

xunit.runner.visualstudio is what supports VSTest. So you'll be using VSTest in your case. But command-line runs will remain using MTP, as well as any client that correctly supports and detects the projects as MTP.

@captainsafia
Copy link
Member

@Youssef1313 I tried this and unfortunately I still run into issues debugging tests in the repo. :/

@danmoseley
Copy link
Member

@Youssef1313 can you repro this with VS Code?

If we can't fix this we'll presumably have to revert your change until we figure it out.

@captainsafia
Copy link
Member

@danmoseley I think we should revert this. microsoft/vscode-dotnettools#1922 has been validated as a bug on the VS Code side and is under investigation.

danmoseley added a commit to danmoseley/aspire that referenced this pull request Apr 16, 2025
@Youssef1313
Copy link
Member Author

@captainsafia I'm not able to reproduce. Added a comment in #8802 (comment)

@Youssef1313
Copy link
Member Author

@captainsafia Meanwhile, while we are trying to figure it out, can you try again the xunit.runner.visualstudio workaround, but also add Microsoft.NET.Test.Sdk? Both packages are needed for VSTest. Sorry I forgot to mention Microsoft.NET.Test.Sdk in my last comment.

danmoseley added a commit that referenced this pull request Apr 16, 2025
…8802)

* Revert "Migrate from VSTest to Microsoft.Testing.Platform (#8498)"

This reverts commit ac098f7.

* revert lines

* patch
Youssef1313 added a commit that referenced this pull request Apr 19, 2025
* Revert "Disable testing platform protocol mode in Workspace (#8825)"

This reverts commit 9a59c69.

* Reapply "Migrate from VSTest to Microsoft.Testing.Platform (#8498)" (#8802)

This reverts commit d2b3016.

* Add xunit.runner.visualstudio

* Temporary workaround
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-engineering-systems infrastructure helix infra engineering repo stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrating to xunit.v3 and to Microsoft.Testing.Platform
10 participants