Skip to content

Commit

Permalink
#412: Explicit parameter from xunit.v3 not working in Visual Studio T…
Browse files Browse the repository at this point in the history
…est Explorer
  • Loading branch information
bradwilson committed Aug 11, 2024
1 parent 6c726eb commit feef548
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TunnelVisionLabsReferenceAssemblyAnnotatorVersion>1.0.0-alpha.160</TunnelVisionLabsReferenceAssemblyAnnotatorVersion>
<XunitAnalyzersVersion>1.16.0-pre.23</XunitAnalyzersVersion>
<XunitV2Version>2.9.1-pre.8</XunitV2Version>
<XunitV3Version>0.2.0-pre.80</XunitV3Version>
<XunitV3Version>0.2.0-pre.87</XunitV3Version>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions src/xunit.runner.visualstudio/Sinks/VsDiscoverySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void Dispose() =>
var fqTestMethodName = $"{testCase.TestClassName}.{testCase.TestMethodName}";
var result = new VsTestCase(fqTestMethodName, uri, source) { DisplayName = Escape(testCase.TestCaseDisplayName) };
result.SetPropertyValue(VsTestRunner.TestCaseUniqueIDProperty, testCase.TestCaseUniqueID);
result.SetPropertyValue(VsTestRunner.TestCaseExplicitProperty, testCase.Explicit);

if (testPlatformContext.DesignMode)
result.SetPropertyValue(VsTestRunner.TestCaseSerializationProperty, testCase.Serialization);
Expand Down
10 changes: 7 additions & 3 deletions src/xunit.runner.visualstudio/Utility/AssemblyRunInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Xunit.Runner.Common;
using Xunit.Sdk;

namespace Xunit.Runner.VisualStudio;

Expand All @@ -11,12 +12,14 @@ public class AssemblyRunInfo
RunSettings runSettings,
string assemblyFileName,
AssemblyMetadata assemblyMetadata,
IList<TestCase>? testCases)
IList<TestCase>? testCases,
bool runExplicitTests)
{
Assembly = new XunitProjectAssembly(project, assemblyFileName, assemblyMetadata);
TestCases = testCases;

runSettings.CopyTo(Assembly.Configuration);
Assembly.Configuration.ExplicitOption = runExplicitTests ? ExplicitOption.On : ExplicitOption.Off;
}

public XunitProjectAssembly Assembly { get; }
Expand All @@ -27,12 +30,13 @@ public class AssemblyRunInfo
XunitProject project,
RunSettings runSettings,
string assemblyFileName,
IList<TestCase>? testCases = null)
IList<TestCase>? testCases = null,
bool runExplicitTests = false)
{
var metadata = AssemblyUtility.GetAssemblyMetadata(assemblyFileName);
if (metadata is null || metadata.XunitVersion == 0)
return null;

return new(project, runSettings, assemblyFileName, metadata, testCases);
return new(project, runSettings, assemblyFileName, metadata, testCases, runExplicitTests);
}
}
6 changes: 5 additions & 1 deletion src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public class VsTestRunner : ITestDiscoverer, ITestExecutor
"xunit.v3.runner.utility.netstandard20.dll",
};

public static TestProperty TestCaseExplicitProperty { get; } =
TestProperty.Register("XunitTestCaseExplicit", "xUnit.net Test Case Explicit Flag", typeof(bool), typeof(VsTestRunner));

public static TestProperty TestCaseSerializationProperty { get; } =
TestProperty.Register("XunitTestCaseSerialization", "xUnit.net Test Case Serialization", typeof(string), typeof(VsTestRunner));

Expand Down Expand Up @@ -382,6 +385,7 @@ public void RunTests(
var logger = new LoggerHelper(frameworkHandle, stopwatch);
var project = new XunitProject();
var runSettings = RunSettings.Parse(runContext?.RunSettings?.SettingsXml);
var runExplicitTests = tests.All(testCase => testCase.GetPropertyValue(TestCaseExplicitProperty, false));

using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), new DiagnosticMessageSink(logger, showInternalDiagnostics: runSettings.InternalDiagnosticMessages ?? false));

Expand All @@ -396,7 +400,7 @@ public void RunTests(
() =>
tests
.GroupBy(testCase => testCase.Source)
.Select(group => AssemblyRunInfo.Create(project, runSettings, group.Key, [.. group]))
.Select(group => AssemblyRunInfo.Create(project, runSettings, group.Key, [.. group], runExplicitTests))
.WhereNotNull()
.ToList()
).GetAwaiter().GetResult();
Expand Down
4 changes: 2 additions & 2 deletions test/test.v3/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class Tests
[Fact]
public void Passing() { }

[Fact]
[Fact(Explicit = true)]
public void Failing() => Assert.Fail("This is a failing test");

[Theory]
[InlineData(true)]
[InlineData(true, Explicit = true)]
[InlineData(false)]
public void ConditionalSkip(bool value) => Assert.SkipWhen(value, "Conditionally skipped");
}

0 comments on commit feef548

Please sign in to comment.