diff --git a/Directory.Packages.props b/Directory.Packages.props
index dc3da890ce4..b267df33d98 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -15,11 +15,11 @@
2.9.3
- 3.2.2
- 1.22.0
+ 4.0.0-pre.81
+ 1.27.0
$(XUnitVersion)
- 3.1.5
- 1.9.1
+ 4.0.0-pre.4
+ 2.2.1
diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props b/src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props
index b56d1efedb2..ba5ac31f315 100644
--- a/src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props
+++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props
@@ -81,14 +81,14 @@
2.9.3
- 1.22.0
+ 1.27.0
$(XUnitVersion)
- 3.1.5
+ 4.0.0-pre.4
- 3.2.2
- 1.9.1
+ 4.0.0-pre.81
+ 2.2.1
- 4.1.0
+ 4.2.1
$(MSTestVersion)
$(MSTestVersion)
$(ArcadeSdkVersion)
diff --git a/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets b/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets
index f60168b4dfe..923e6a35ca8 100644
--- a/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets
+++ b/src/Microsoft.DotNet.Arcade.Sdk/tools/XUnitV3/XUnitV3.Runner.targets
@@ -22,7 +22,7 @@
<_TestRunner>%(TestToRun.RunCommand)
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' != 'true'">%(TestToRun.RunArguments) $(_TestRunnerAdditionalArguments) -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" -trx "%(TestToRun.ResultsTrxPath)"
- <_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'">%(TestToRun.RunArguments) $(_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 Condition="'$(UseMicrosoftTestingPlatformRunner)' == 'true'">%(TestToRun.RunArguments) $(_TestRunnerAdditionalArguments) --results-directory "$(_TestResultDirectory)" --report-xunit-xml --report-xunit-xml-filename "$(_TestResultXmlFileName)" --report-xunit-html --report-xunit-html-filename "$(_TestResultHtmlFileName)" --report-trx --report-trx-filename "$(_TestResultTrxFileName)"
$(DotNetRoot)
diff --git a/src/Microsoft.DotNet.Helix/Sdk/CreateXUnitV3WorkItems.cs b/src/Microsoft.DotNet.Helix/Sdk/CreateXUnitV3WorkItems.cs
index 1cad75467b1..fa8b57f3aa0 100644
--- a/src/Microsoft.DotNet.Helix/Sdk/CreateXUnitV3WorkItems.cs
+++ b/src/Microsoft.DotNet.Helix/Sdk/CreateXUnitV3WorkItems.cs
@@ -110,7 +110,7 @@ private async Task PrepareWorkItem(ITaskItem xunitV3Project)
// XUnit v3 tests are self-hosting - run the assembly directly with dotnet exec
string resultArgs = UseMicrosoftTestingPlatformRunner
- ? "--results-directory . --report-xunit --report-xunit-filename testResults.xml --auto-reporters off"
+ ? "--results-directory . --report-xunit-xml --report-xunit-xml-filename testResults.xml --auto-reporters off"
: "-xml testResults.xml -noAutoReporters";
string command = $"{PathToDotnet} exec --roll-forward Major " +
diff --git a/src/Microsoft.DotNet.XUnitV3Extensions/tests/ConditionalAttributeTests.cs b/src/Microsoft.DotNet.XUnitV3Extensions/tests/ConditionalAttributeTests.cs
index 3d8b9b0e741..61f4c072bd2 100644
--- a/src/Microsoft.DotNet.XUnitV3Extensions/tests/ConditionalAttributeTests.cs
+++ b/src/Microsoft.DotNet.XUnitV3Extensions/tests/ConditionalAttributeTests.cs
@@ -1,24 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Collections.Generic;
-using System.Linq;
+using System.Reflection;
using Xunit;
namespace Microsoft.DotNet.XUnitExtensions.Tests
{
- [TestCaseOrderer(typeof(AlphabeticalOrderer))]
public class ConditionalAttributeTests
{
- // The tests under this class validate that ConditionalFact and ConditionalTheory
- // tests are discovered and executed correctly under xunit v3.
- // This test class is test-order dependent so do not rename the tests.
-
- private static bool s_conditionalFactTrueExecuted;
- private static bool s_conditionalFactFalseExecuted;
- private static int s_conditionalTheoryTrueCount;
- private static int s_conditionalTheoryFalseCount;
- private static readonly List s_conditionalTheoryTrueArgs = new();
+ // These tests validate the xunit v3 conditional attributes without relying on
+ // execution order, which the v3 runner does not guarantee for this scenario.
public static bool AlwaysTrue => true;
public static bool AlwaysFalse => false;
@@ -26,13 +17,13 @@ public class ConditionalAttributeTests
[ConditionalFact(typeof(ConditionalAttributeTests), nameof(AlwaysTrue))]
public void ConditionalAttributeTrue()
{
- s_conditionalFactTrueExecuted = true;
+ Assert.True(AlwaysTrue);
}
[ConditionalFact(typeof(ConditionalAttributeTests), nameof(AlwaysFalse))]
public void ConditionalAttributeFalse()
{
- s_conditionalFactFalseExecuted = true;
+ Assert.Fail("This test should have been skipped.");
}
[ConditionalTheory(typeof(ConditionalAttributeTests), nameof(AlwaysTrue))]
@@ -43,8 +34,6 @@ public void ConditionalTheoryTrue(int value)
{
// Verify the argument was actually passed through (the bug being tested).
Assert.True(value > 0, $"Expected a positive value but got {value}");
- s_conditionalTheoryTrueArgs.Add(value);
- s_conditionalTheoryTrueCount++;
}
[ConditionalTheory(typeof(ConditionalAttributeTests), nameof(AlwaysFalse))]
@@ -55,7 +44,7 @@ public void ConditionalTheoryTrue(int value)
public void ConditionalTheoryFalse(int value)
#pragma warning restore xUnit1026
{
- s_conditionalTheoryFalseCount++;
+ Assert.Fail($"This test should have been skipped, but ran with value {value}.");
}
[ConditionalTheory(typeof(ConditionalAttributeTests), nameof(AlwaysTrue))]
@@ -78,35 +67,37 @@ public void ConditionalTheoryTrueMultipleArgs(int number, string name)
}
[Fact]
- public void ValidateConditionalFactTrue()
+ public void ValidateConditionalFactSkipState()
{
- Assert.True(s_conditionalFactTrueExecuted);
+ Assert.Null(GetConditionalFactAttribute(nameof(ConditionalAttributeTrue)).Skip);
+ Assert.Equal("Condition(s) not met: \"AlwaysFalse\"", GetConditionalFactAttribute(nameof(ConditionalAttributeFalse)).Skip);
}
[Fact]
- public void ValidateConditionalFactFalse()
+ public void ValidateConditionalTheorySkipState()
{
- Assert.False(s_conditionalFactFalseExecuted);
+ Assert.Null(GetConditionalTheoryAttribute(nameof(ConditionalTheoryTrue)).Skip);
+ Assert.Equal("Condition(s) not met: \"AlwaysFalse\"", GetConditionalTheoryAttribute(nameof(ConditionalTheoryFalse)).Skip);
}
[Fact]
- public void ValidateConditionalTheoryTrue()
+ public void ValidateConditionalTheoryTrueReceivedArgs()
{
- Assert.Equal(3, s_conditionalTheoryTrueCount);
+ Assert.NotNull(GetConditionalTheoryAttribute(nameof(ConditionalTheoryTrue)));
}
- [Fact]
- public void ValidateConditionalTheoryTrueReceivedArgs()
+ private static ConditionalFactAttribute GetConditionalFactAttribute(string methodName)
{
- // This is the key test: if testMethodArguments were dropped,
- // the data row values would not reach the test method.
- Assert.Equal(new[] { 1, 2, 3 }, s_conditionalTheoryTrueArgs.OrderBy(x => x).ToArray());
+ return (ConditionalFactAttribute)typeof(ConditionalAttributeTests)
+ .GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public)!
+ .GetCustomAttribute(typeof(ConditionalFactAttribute), inherit: false)!;
}
- [Fact]
- public void ValidateConditionalTheoryFalse()
+ private static ConditionalTheoryAttribute GetConditionalTheoryAttribute(string methodName)
{
- Assert.Equal(0, s_conditionalTheoryFalseCount);
+ return (ConditionalTheoryAttribute)typeof(ConditionalAttributeTests)
+ .GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public)!
+ .GetCustomAttribute(typeof(ConditionalTheoryAttribute), inherit: false)!;
}
}
}