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

Support xUnit v3 #199

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

reduckted
Copy link
Contributor

This pull request adds support for xUnit v3, which was recently released.

The code to use xUnit v3 was almost identical to that needed for xUnit v2, so rather than duplicating everything, I've created shared projects and used a few conditional compilation blocks to handle v2 or v3 specific scenarios.

Project changes:

  • Everything except for Usings.cs and MockedVS.cs in Microsoft.VisualStudio.Sdk.TestFramework.Xunit has been moved to Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Shared.
  • Likewise, everything except for Usings.cs in Microsoft.VisualStudio.Sdk.TestFramework.Tests has been moved to Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared.
  • Microsoft.VisualStudio.Sdk.TestFramework.Tests has been renamed to Microsoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.
  • A new Microsoft.VisualStudio.Sdk.TestFramework.Xunit.V3 project has been added, along with its corresponding test project Microsoft.VisualStudio.Sdk.TestFramework.Xunit.V3.Tests.

Code changes:

  • BrokeredServiceContractTestBase implements IAsyncLifetime. In xUnit v2, this used Task-based methods. In xUnit v3, this uses ValueTask-based methods, so conditional compilation was used to defines the different method signatures. The actual implementations of those methods are unchanged.
  • MefHosting had two issues that needed to be addressed.
    1. In xUnit v3, test projects are built as executables instead of libraries, so when looking for the default assembly names, we need to look at .exe files as well as .dll files.
    2. For some reason (I couldn't work out why), some assemblies would fail to load via Assembly.Load with a FileNotFoundException. The assemblies in question were the Mono.* assemblies that xUnit v3 uses, as well as a couple of the xunit.* assemblies. They exist in the current directory (that's how they were found to be the default assemblies to load), but could not be loaded. To work around this problem, when loading an assembly fails with a FileNotFoundException, then it will look for the file on disk, load its contents into a byte array, then use Assembly.Load(byte[]) to load the assembly.
  • TestFrameworkTests had a number of xUnit1051 warnings. This was solved by using CancellationToken.None for xUnit v2 and TestContext.Current.CancellationToken for xUnit v3.
  • VsActivityLogTests had an interesting bug. The NoForwarder test would succeed when run by itself, but when run with the WithForwarder and/or WithXunitAdapter tests, the test would fail with an error stating that "There is no currently active test.". This seems to be a result of the ITestOutputHelper being perhaps a bit more strict in xUnit v3 and throwing exceptions when you try to write to it after the test has completed. The problem was that the WithForwarder and WithXunitAdapter tests were setting the ForwardTo property on the MockVsActivityLog instance. That instance comes from the GlobalServiceProvider which is shared between those three tests. If NoForwarder runs last (which it always seemed to do), then the activity log would actually be forwarding to the ITestOutputHelper which was created for a different test. The fix I've put in place is to set the ForwardTo property to null when the GlobalServiceProvider is reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant