Skip to content

Commit

Permalink
#422: Add XunitSkipReason property to VSTest test case
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Oct 30, 2024
1 parent 3d3b241 commit d5676ac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/xunit.runner.visualstudio/Sinks/VsDiscoverySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public void Dispose() =>
result.SetPropertyValue(VsTestRunner.ManagedTypeProperty, testCase.TestClassName);
result.SetPropertyValue(VsTestRunner.ManagedMethodProperty, managedMethodName);

if (testCase.SkipReason is not null)
result.SetPropertyValue(VsTestRunner.SkipReasonProperty, testCase.SkipReason);

if (testPlatformContext.DesignMode)
result.SetPropertyValue(VsTestRunner.TestCaseSerializationProperty, testCase.Serialization);

Expand Down
3 changes: 3 additions & 0 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public class VsTestRunner : ITestDiscoverer, ITestExecutor
public static TestProperty ManagedTypeProperty { get; } =
TestProperty.Register("TestCase.ManagedType", "ManagedType", string.Empty, string.Empty, typeof(string), x => !string.IsNullOrWhiteSpace(x as string), TestPropertyAttributes.Hidden, typeof(TestCase));

public static TestProperty SkipReasonProperty { get; } =
TestProperty.Register("XunitSkipReason", "xUnit.net Skip Reason", typeof(string), typeof(VsTestRunner));

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

Expand Down
11 changes: 11 additions & 0 deletions test/test.xunit.runner.visualstudio/Sinks/VsDiscoverySinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,16 @@ public void SetsManagedTypeAndMethodProperties(
Assert.Equal("test-class-name", vsTestCase.GetPropertyValue(VsTestRunner.ManagedTypeProperty));
Assert.Equal(expectedManagedMethodName, vsTestCase.GetPropertyValue(VsTestRunner.ManagedMethodProperty));
}

[Fact]
public void SetsSkipReason()
{
var testCase = TestData.TestCaseDiscovered(skipReason: "the-skip-reason");

var vsTestCase = VsDiscoverySink.CreateVsTestCase("source", testCase, logger, testPlatformContext);

Assert.NotNull(vsTestCase);
Assert.Equal("the-skip-reason", vsTestCase.GetPropertyValue(VsTestRunner.SkipReasonProperty));
}
}
}

0 comments on commit d5676ac

Please sign in to comment.