Skip to content

Move to xunit.v3 #13540

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 27 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PublishWindowsPdb>false</PublishWindowsPdb>

<DefaultAppHostRuntimeIdentifier Condition="'$(TargetArchitecture)'!=''">win-$(TargetArchitecture)</DefaultAppHostRuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
Expand Down Expand Up @@ -66,6 +68,10 @@
<ExcludeByFile />
</PropertyGroup>

<PropertyGroup>
<TestRunnerName>XUnitV3</TestRunnerName>
</PropertyGroup>

<!-- workaround for package downgrade in Microsoft.NetCore.Platforms -->
<PropertyGroup>
<DisableImplicitNETCorePlatformsReference>true</DisableImplicitNETCorePlatformsReference>
Expand Down
14 changes: 3 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<PackageVersion Include="AwesomeAssertions" Version="$(AwesomeAssertionsVersion)" />
<PackageVersion Include="Moq" Version="$(MoqPackageVersion)" />
<PackageVersion Include="Microsoft.DotNet.RemoteExecutor" Version="$(MicrosoftDotNetRemoteExecutorVersion)" />
<PackageVersion Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.DotNet.XUnitV3Extensions" Version="$(MicrosoftDotNetXUnitV3ExtensionsPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="$(MicrosoftVisualStudioThreadingVersion)" />
<PackageVersion Include="Verify.Xunit" Version="$(VerifyXunitVersion)" />
<PackageVersion Include="xunit.assert" Version="$(XUnitAssertVersion)" Condition="'$(IsTestProject)' != 'true'" />
<PackageVersion Include="Verify.XunitV3" Version="$(VerifyXunitV3Version)" />
<PackageVersion Include="xunit.v3.assert" Version="$(XUnitV3Version)" Condition="'$(IsTestProject)' != 'true'" />
<PackageVersion Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" />

<!-- Code coverage-->
Expand All @@ -50,10 +50,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
Expand All @@ -66,10 +62,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(MicrosoftCodeAnalysisPublicApiAnalyzersVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.SourceGenerators.Testing.XUnit" Version="$(MicrosoftCodeAnalysisPackagesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(MicrosoftCodeAnalysisVisualBasicWorkspacesVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageVersion Include="NuGet.Packaging" Version="$(NugetPackagingVersion)" />
Expand Down
2 changes: 2 additions & 0 deletions eng/Test.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<!-- Making all tests run sequentially until we regroup tests. Tracked under issue https://github.com/dotnet/winforms/issues/8810. -->
<PropertyGroup>
<XUnitCoreSettingsFile>$(RepositoryEngineeringDir)xunit.runner.json</XUnitCoreSettingsFile>

<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<!--
Dependencies registered here by Name and Uri will be updated by Maestro via darc update-dependencies
They will be updated either in eng/Versions.props (most) or in global.json (for example: Microsoft.DotNet.Arcade.Sdk)
Note: if the Uri is a new place, you will need to add a subscription from that place to us in the appropriate channel
Expand Down Expand Up @@ -103,7 +103,7 @@ Note: if the Uri is a new place, you will need to add a subscription from that p
<Uri>https://github.com/dotnet/dotnet</Uri>
<Sha>25bec1af21db71468c5c2c3a588dd54d0e058e9d</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XUnitExtensions" Version="10.0.0-beta.25311.107">
<Dependency Name="Microsoft.DotNet.XUnitV3Extensions" Version="10.0.0-beta.25311.107">
<Uri>https://github.com/dotnet/dotnet</Uri>
<Sha>25bec1af21db71468c5c2c3a588dd54d0e058e9d</Sha>
</Dependency>
Expand Down
16 changes: 8 additions & 8 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@
<PropertyGroup>
<MicrosoftDotNetGenFacadesPackageVersion>10.0.0-beta.25311.107</MicrosoftDotNetGenFacadesPackageVersion>
<MicrosoftDotNetRemoteExecutorVersion>10.0.0-beta.25311.107</MicrosoftDotNetRemoteExecutorVersion>
<MicrosoftDotNetXUnitExtensionsPackageVersion>10.0.0-beta.25311.107</MicrosoftDotNetXUnitExtensionsPackageVersion>
<MicrosoftDotNetXUnitV3ExtensionsPackageVersion>10.0.0-beta.25311.107</MicrosoftDotNetXUnitV3ExtensionsPackageVersion>
<MicrosoftNETTestSdkVersion>17.4.0-preview-20220707-01</MicrosoftNETTestSdkVersion>
</PropertyGroup>
<!-- Below have no corresponding entries in Versions.Details.XML because they are not updated via Maestro -->
<!-- XUnit-related (not extensions) -->
<PropertyGroup>
<XUnitVersion>2.9.2</XUnitVersion>
<XUnitAssertVersion>$(XUnitVersion)</XUnitAssertVersion>
<XUnitRunnerConsoleVersion>$(XUnitVersion)</XUnitRunnerConsoleVersion>
<XUnitRunnerVisualStudioVersion>2.8.1</XUnitRunnerVisualStudioVersion>
<XUnitExtensibilityExecutionVersion>$(XUnitVersion)</XUnitExtensibilityExecutionVersion>
<XUnitStaFactPackageVersion>1.2.46-alpha</XUnitStaFactPackageVersion>
<XUnitV3Version>2.0.2</XUnitV3Version>
<XUnitRunnerVisualStudioVersion>3.1.0</XUnitRunnerVisualStudioVersion>
<XUnitStaFactPackageVersion>2.1.7</XUnitStaFactPackageVersion>
</PropertyGroup>
<!-- Test related -->
<PropertyGroup>
Expand All @@ -71,7 +68,10 @@
<SystemComponentModelTypeConverterTestDataVersion>10.0.0-beta.24568.1</SystemComponentModelTypeConverterTestDataVersion>
<SystemDrawingCommonTestDataVersion>10.0.0-beta.24568.1</SystemDrawingCommonTestDataVersion>
<SystemWindowsExtensionsTestDataVersion>10.0.0-beta.24568.1</SystemWindowsExtensionsTestDataVersion>
<VerifyXunitVersion>25.0.1</VerifyXunitVersion>
<VerifyXunitV3Version>30.1.0</VerifyXunitV3Version>

<!-- Temporary: Remove once https://github.com/dotnet/arcade/pull/15904 flows to the repo -->
<XUnitV3Version>2.0.3</XUnitV3Version>
</PropertyGroup>
<!-- Code Coverage -->
<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/build-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
$(_OfficialBuildIdArgs)
$(_InternalRuntimeDownloadArgs)
/p:Coverage=$(_Coverage)
/p:TestRunnerAdditionalArguments='-notrait Category=IgnoreForCI -notrait Category=failing'
/p:TestRunnerAdditionalArguments='--filter-not-trait Category=IgnoreForCI --filter-not-trait Category=failing'
/bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\Test-${{ parameters.targetArchitecture }}.binlog
/m:1
displayName: Run Unit Tests
Expand All @@ -107,7 +107,7 @@ jobs:
$(_OfficialBuildIdArgs)
$(_InternalRuntimeDownloadArgs)
/p:Coverage=$(_Coverage)
/p:TestRunnerAdditionalArguments='-notrait Category=IgnoreForCI -notrait Category=failing'
/p:TestRunnerAdditionalArguments='--filter-not-trait Category=IgnoreForCI --filter-not-trait Category=failing'
/bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\IntegrationTest-${{ parameters.targetArchitecture }}.binlog
/m:1
env:
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
$(_OfficialBuildIdArgs)
$(_InternalRuntimeDownloadArgs)
/p:Coverage=$(_Coverage)
/p:TestRunnerAdditionalArguments='-notrait Category=IgnoreForCI -notrait Category=failing'
/p:TestRunnerAdditionalArguments='--filter-not-trait Category=IgnoreForCI --filter-not-trait Category=failing'
/bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\Test-${{ parameters.targetArchitecture }}.binlog
/m:1
displayName: Run Unit Tests
Expand All @@ -110,7 +110,7 @@ jobs:
$(_OfficialBuildIdArgs)
$(_InternalRuntimeDownloadArgs)
/p:Coverage=$(_Coverage)
/p:TestRunnerAdditionalArguments='-notrait Category=IgnoreForCI -notrait Category=failing'
/p:TestRunnerAdditionalArguments='--filter-not-trait Category=IgnoreForCI --filter-not-trait Category=failing'
/bl:$(BUILD.SOURCESDIRECTORY)\artifacts\log\$(_BuildConfig)\IntegrationTest-${{ parameters.targetArchitecture }}.binlog
/m:1
env:
Expand Down
9 changes: 6 additions & 3 deletions src/Common/tests/TestUtilities/CommonTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static TheoryData<Point> GetPointTheoryData(TestIncludeType includeType)
TheoryData<Point> data = new();
if (!includeType.HasFlag(TestIncludeType.NoPositives))
{
data.Add(default);
data.Add(default(Point));
data.Add(new Point(10));
data.Add(new Point(1, 2));
}
Expand All @@ -99,7 +99,7 @@ public static TheoryData<Size> GetSizeTheoryData(TestIncludeType includeType)
TheoryData<Size> data = new();
if (!includeType.HasFlag(TestIncludeType.NoPositives))
{
data.Add(default);
data.Add(default(Size));
data.Add(new Size(new Point(1, 1)));
data.Add(new Size(1, 2));
}
Expand All @@ -126,7 +126,10 @@ public static TheoryData<Size> GetSizeTheoryData(TestIncludeType includeType)
public static TheoryData<EventArgs?> GetEventArgsTheoryData()
=> new()
{
null,
// Cast is important. This calls Add(TheoryDataRow<T>) method.
// Without the cast, this will pass a null TheoryDataRow<EventArgs> to the method.
// With the cast, implicit conversion from null EventArgs to TheoryDataRow<EventArgs> is used.
(EventArgs?)null,
new EventArgs()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<ItemGroup>
<PackageReference Include="AwesomeAssertions" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit.assert" />
<PackageReference Include="xunit.v3.assert" />
<PackageReference Include="xunit.stafact" />
<PackageReference Include="Microsoft.DotNet.RemoteExecutor" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" />
<PackageReference Include="Microsoft.DotNet.XUnitV3Extensions" />
<PackageReference Include="System.Formats.Nrbf" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using Xunit.v3;

namespace Xunit;

Expand All @@ -11,29 +11,15 @@ namespace Xunit;
/// We cannot inherit from <see cref="MemberDataAttribute"/> as it is sealed, so we have to reimplement
/// ConvertDataItem inheriting from MemberDataAttributeBase.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class CommonMemberDataAttribute : MemberDataAttributeBase
{
public CommonMemberDataAttribute(Type memberType, string memberName = "TheoryData")
: this(memberType, memberName, null) { }
: this(memberType, memberName, Array.Empty<object>()) { }

public CommonMemberDataAttribute(Type memberType, string memberName, params object[]? parameters)
public CommonMemberDataAttribute(Type memberType, string memberName, params object?[] parameters)
: base(memberName, parameters)
{
MemberType = memberType;
}

protected override object[]? ConvertDataItem(MethodInfo testMethod, object? item)
{
if (item is null)
{
return null;
}

if (item is not object[] array)
{
throw new ArgumentException($"Property {MemberName} on {MemberType ?? testMethod.DeclaringType} yielded an item that is not an object[], but {item.GetType().Name}");
}

return array;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class NormalizedStringDataAttribute : CommonMemberDataAttribute
{
public NormalizedStringDataAttribute() : base(typeof(NormalizedStringDataAttribute)) { }

public static ReadOnlyTheoryData TheoryData { get; } = new(new TheoryData<string?, string>()
{
{ null, string.Empty },
{ string.Empty, string.Empty },
{ "teststring", "teststring" }
});
public static IEnumerable<TheoryDataRow<string?, string>> TheoryData { get; } =
[
new(null, string.Empty),
new(string.Empty, string.Empty),
new("teststring", "teststring")
];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit.Sdk;
using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;
using Xunit.v3;

namespace Xunit;

Expand All @@ -14,9 +16,24 @@ namespace Xunit;
/// <see cref="TestArchitectures.X64"/>. See https://github.com/dotnet/winforms/issues/7013.
/// </para>
/// </remarks>
[TraitDiscoverer("System.SkipOnArchitectureDiscoverer", "System.Windows.Forms.TestUtilities")]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class SkipOnArchitectureAttribute : Attribute, ITraitAttribute
{
public SkipOnArchitectureAttribute(TestArchitectures testArchitectures, string reason) { }
private readonly TestArchitectures _testArchitectures;

public SkipOnArchitectureAttribute(TestArchitectures testArchitectures, string reason)
{
_testArchitectures = testArchitectures;
}

public IReadOnlyCollection<KeyValuePair<string, string>> GetTraits()
{
if ((_testArchitectures.HasFlag(TestArchitectures.X86) && RuntimeInformation.ProcessArchitecture == Architecture.X86)
|| (_testArchitectures.HasFlag(TestArchitectures.X64) && RuntimeInformation.ProcessArchitecture == Architecture.X64))
{
return new[] { new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.IgnoreForCI) };
}

return Array.Empty<KeyValuePair<string, string>>();
}
}

This file was deleted.

6 changes: 3 additions & 3 deletions src/Common/tests/TestUtilities/XUnit/UseCultureAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit.Sdk;
using Xunit.v3;

namespace Xunit;

Expand Down Expand Up @@ -69,7 +69,7 @@ public UseCultureAttribute(string culture, string uiCulture)
/// and replaces them with the new cultures defined in the constructor.
/// </summary>
/// <param name="methodUnderTest">The method under test</param>
public override unsafe void Before(MethodInfo methodUnderTest)
public override unsafe void Before(MethodInfo methodUnderTest, IXunitTest test)
{
_originalCulture = Thread.CurrentThread.CurrentCulture;
_originalUICulture = Thread.CurrentThread.CurrentUICulture;
Expand All @@ -93,7 +93,7 @@ public override unsafe void Before(MethodInfo methodUnderTest)
/// <see cref="CultureInfo.CurrentUICulture" /> to <see cref="Thread.CurrentPrincipal" />
/// </summary>
/// <param name="methodUnderTest">The method under test</param>
public override void After(MethodInfo methodUnderTest)
public override void After(MethodInfo methodUnderTest, IXunitTest test)
{
Thread.CurrentThread.CurrentCulture = _originalCulture;
Thread.CurrentThread.CurrentUICulture = _originalUICulture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<OptionStrict>On</OptionStrict>
<MyType>WindowsFormsWithCustomSubMain</MyType>
<UseApplicationFramework>True</UseApplicationFramework>
<OutputType>Library</OutputType>
<RootNamespace></RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" />
<PackageReference Include="Microsoft.DotNet.XUnitV3Extensions" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading