Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<!-- Overwrite XUnitVersion/XUnitAnalyzersVersion/XUnitRunnerConsoleVersion/XUnitRunnerVisualStudioVersion/MicrosoftTestingPlatformVersion that comes from the Arcade SDK to be in sync as Arcade doesn't use a live Arcade SDK.
Keep in sync with DefaultVersions.props. -->
<XUnitVersion>2.9.3</XUnitVersion>
<XUnitV3Version>3.2.2</XUnitV3Version>
<XUnitAnalyzersVersion>1.22.0</XUnitAnalyzersVersion>
<XUnitV3Version>4.0.0-pre.81</XUnitV3Version>
<XUnitAnalyzersVersion>1.27.0</XUnitAnalyzersVersion>
<XUnitRunnerConsoleVersion>$(XUnitVersion)</XUnitRunnerConsoleVersion>
<XUnitRunnerVisualStudioVersion>3.1.5</XUnitRunnerVisualStudioVersion>
<MicrosoftTestingPlatformVersion>1.9.1</MicrosoftTestingPlatformVersion>
<XUnitRunnerVisualStudioVersion>4.0.0-pre.4</XUnitRunnerVisualStudioVersion>
<MicrosoftTestingPlatformVersion>2.2.1</MicrosoftTestingPlatformVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@

<!-- Follow the instructions on how to update any of the below xunit versions: https://github.com/dotnet/arcade/blob/main/Documentation/update-xunit.md. -->
<XUnitVersion Condition="'$(XUnitVersion)' == ''">2.9.3</XUnitVersion>
<XUnitAnalyzersVersion Condition="'$(XUnitAnalyzersVersion)' == ''">1.22.0</XUnitAnalyzersVersion>
<XUnitAnalyzersVersion Condition="'$(XUnitAnalyzersVersion)' == ''">1.27.0</XUnitAnalyzersVersion>
<XUnitRunnerConsoleVersion Condition="'$(XUnitRunnerConsoleVersion)' == ''">$(XUnitVersion)</XUnitRunnerConsoleVersion>
<XUnitRunnerVisualStudioVersion Condition="'$(XUnitRunnerVisualStudioVersion)' == ''">3.1.5</XUnitRunnerVisualStudioVersion>
<XUnitRunnerVisualStudioVersion Condition="'$(XUnitRunnerVisualStudioVersion)' == ''">4.0.0-pre.4</XUnitRunnerVisualStudioVersion>

<XUnitV3Version Condition="'$(XUnitV3Version)' == ''">3.2.2</XUnitV3Version>
<MicrosoftTestingPlatformVersion Condition="'$(MicrosoftTestingPlatformVersion)' == ''">1.9.1</MicrosoftTestingPlatformVersion>
<XUnitV3Version Condition="'$(XUnitV3Version)' == ''">4.0.0-pre.81</XUnitV3Version>
<MicrosoftTestingPlatformVersion Condition="'$(MicrosoftTestingPlatformVersion)' == ''">2.2.1</MicrosoftTestingPlatformVersion>

<MSTestVersion Condition="'$(MSTestVersion)' == ''">4.1.0</MSTestVersion>
<MSTestVersion Condition="'$(MSTestVersion)' == ''">4.2.1</MSTestVersion>
<MSTestTestAdapterVersion Condition="'$(MSTestTestAdapterVersion)' == ''">$(MSTestVersion)</MSTestTestAdapterVersion>
<MSTestTestFrameworkVersion Condition="'$(MSTestTestFrameworkVersion)' == ''">$(MSTestVersion)</MSTestTestFrameworkVersion>
<MicrosoftDotNetBuildTasksFeedVersion Condition="'$(MicrosoftDotNetBuildTasksFeedVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetBuildTasksFeedVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<_TestRunner>%(TestToRun.RunCommand)</_TestRunner>
<_TestRunnerArgs Condition="'$(UseMicrosoftTestingPlatformRunner)' != 'true'">%(TestToRun.RunArguments) $(_TestRunnerAdditionalArguments) -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" -trx "%(TestToRun.ResultsTrxPath)"</_TestRunnerArgs>
<_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>
<_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)"</_TestRunnerArgs>

<TestDotNetRoot Condition="'$(TestDotNetRoot)' == ''">$(DotNetRoot)</TestDotNetRoot>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.DotNet.Helix/Sdk/CreateXUnitV3WorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private async Task<ITaskItem> 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 " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
// 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<int> s_conditionalTheoryTrueArgs = new();
// These tests validate the xunit v3 conditional attributes without relying on
Comment thread
agocke marked this conversation as resolved.
// execution order, which the v3 runner does not guarantee for this scenario.

public static bool AlwaysTrue => true;
public static bool AlwaysFalse => false;

[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))]
Expand All @@ -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))]
Expand All @@ -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))]
Expand All @@ -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)!;
}
}
}
Loading