Skip to content
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

Compatibility issue between xunit.v3 and MSTest projects #4693

Open
KirkMunroSagent opened this issue Jan 17, 2025 · 3 comments
Open

Compatibility issue between xunit.v3 and MSTest projects #4693

KirkMunroSagent opened this issue Jan 17, 2025 · 3 comments
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library

Comments

@KirkMunroSagent
Copy link

Describe the bug

If you have a csproj file containing MSTest unit tests, and you include the new xunit.v3 package (the xunit team changed their package name when they came out with v3), an AutoRegisteredExtensions.cs file is generated that will not compile, with the compiler complaining that TestingPlatformBuilderHook does not exist in Microsoft.VisualStudio.TestTools.UnitTesting.

Steps To Reproduce

Note: This is how I think it should be reproducible based on my understanding of the issue; however, I haven't tested these steps. I simply did a package reference inspection when I realized that it was probably my package management changes that caused the issue locally, undid those changes, and then added the packages back one-by-one until the issue repro'ed.

  1. Create an MSTest project with a simple test.
  2. Add a package reference in your project to xunit.v3.
  3. Build your project.

Expected behavior

The project should build.

Actual behavior

The project fails with the error specified above.

Additional context

This does not happen using the xunit package. The xUnit team has two package naming schemes: xunit* for versions 1 and 2, and xunit.v3* for version 3. I updated to xunit v3 today and ran into this issue, when I learned that I had a package reference to xunit.v3 that was unnecessary (my project where this fails uses MSTest tests exclusively.

@nohwnd
Copy link
Member

nohwnd commented Jan 17, 2025

Using two different frameworks in the same project is not a supported scenario in the new testing platform. Is this something you accidentally found out, or is there a use case where you need to mix xunit tests and mstest tests in the same assembly?

@KirkMunroSagent
Copy link
Author

KirkMunroSagent commented Jan 17, 2025

This was purely accidental.

I had a Directory.Build.props file that was adding package references using a condition, and the condition was picking up a project that I didn't expect, so xunit (and then xunit.v3 once I updated to that version) was added to that MSTest project accidentally.

What's interesting about this is that having a reference to xunit didn't cause an issue. So it took me quite a bit of time to figure out what was causing a compilation failure in this project, especially since the package reference was being added through a Build.props file and not in the csproj itself. The obscurity of the error made me think maybe there was an opportunity for improvement here, not to support both, but perhaps to produce a more appropriate compilation error.

Anyway, this issue is purely an issue from having an unintended package reference...there was no xunit code in the project I was working on. I've corrected that and no longer have an issue, but I wanted to report it here just the same. At least it might result in someone searching for this problem at some point coming across this ticket to better understand what is going on.

@nohwnd
Copy link
Member

nohwnd commented Jan 17, 2025

Thanks for reporting, yes the error could definitely be better, especially if we don't plan to support it.

@nohwnd nohwnd added Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library and removed Needs: Author Feedback labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Testing Platform Belongs to the Microsoft.Testing.Platform core library
Projects
None yet
Development

No branches or pull requests

3 participants