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.
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:
Usings.cs
andMockedVS.cs
inMicrosoft.VisualStudio.Sdk.TestFramework.Xunit
has been moved toMicrosoft.VisualStudio.Sdk.TestFramework.Xunit.Shared
.Usings.cs
inMicrosoft.VisualStudio.Sdk.TestFramework.Tests
has been moved toMicrosoft.VisualStudio.Sdk.TestFramework.Xunit.Tests.Shared
.Microsoft.VisualStudio.Sdk.TestFramework.Tests
has been renamed toMicrosoft.VisualStudio.Sdk.TestFramework.Xunit.Tests
.Microsoft.VisualStudio.Sdk.TestFramework.Xunit.V3
project has been added, along with its corresponding test projectMicrosoft.VisualStudio.Sdk.TestFramework.Xunit.V3.Tests
.Code changes:
BrokeredServiceContractTestBase
implementsIAsyncLifetime
. In xUnit v2, this usedTask
-based methods. In xUnit v3, this usesValueTask
-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..exe
files as well as.dll
files.Assembly.Load
with aFileNotFoundException
. The assemblies in question were theMono.*
assemblies that xUnit v3 uses, as well as a couple of thexunit.*
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 aFileNotFoundException
, then it will look for the file on disk, load its contents into a byte array, then useAssembly.Load(byte[])
to load the assembly.TestFrameworkTests
had a number ofxUnit1051
warnings. This was solved by usingCancellationToken.None
for xUnit v2 andTestContext.Current.CancellationToken
for xUnit v3.VsActivityLogTests
had an interesting bug. TheNoForwarder
test would succeed when run by itself, but when run with theWithForwarder
and/orWithXunitAdapter
tests, the test would fail with an error stating that "There is no currently active test.". This seems to be a result of theITestOutputHelper
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 theWithForwarder
andWithXunitAdapter
tests were setting theForwardTo
property on theMockVsActivityLog
instance. That instance comes from theGlobalServiceProvider
which is shared between those three tests. IfNoForwarder
runs last (which it always seemed to do), then the activity log would actually be forwarding to theITestOutputHelper
which was created for a different test. The fix I've put in place is to set theForwardTo
property to null when theGlobalServiceProvider
is reset.