Created
February 1, 2021 21:41
-
-
Save mthalman/2de08d4c56ddec13091eeffb438689e5 to your computer and use it in GitHub Desktop.
Skip tests for empty theory data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Licensed to the .NET Foundation under one or more agreements. | |
| // The .NET Foundation licenses this file to you under the MIT license. | |
| using System; | |
| using Xunit; | |
| using Xunit.Sdk; | |
| namespace Microsoft.DotNet.Docker.Tests | |
| { | |
| [XunitTestCaseDiscoverer("Microsoft.DotNet.Docker.Tests.DotNetTheoryDiscoverer", "Microsoft.DotNet.Docker.Tests")] | |
| [AttributeUsage(AttributeTargets.Method)] | |
| public class DotNetTheoryAttribute : TheoryAttribute | |
| { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Licensed to the .NET Foundation under one or more agreements. | |
| // The .NET Foundation licenses this file to you under the MIT license. | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using Xunit.Abstractions; | |
| using Xunit.Sdk; | |
| namespace Microsoft.DotNet.Docker.Tests | |
| { | |
| public class DotNetTheoryDiscoverer : TheoryDiscoverer | |
| { | |
| public DotNetTheoryDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) | |
| { | |
| } | |
| public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) | |
| { | |
| IEnumerable<IXunitTestCase> results = base.Discover(discoveryOptions, testMethod, theoryAttribute); | |
| if (results.Count() == 1 && | |
| results.First() is ExecutionErrorTestCase errorTestCase && | |
| errorTestCase.ErrorMessage.StartsWith("No data found for")) | |
| { | |
| return CreateTestCasesForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, Array.Empty<object>(), errorTestCase.ErrorMessage); | |
| } | |
| return results; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment