Skip to content

Instantly share code, notes, and snippets.

@mthalman
Created February 1, 2021 21:41
Show Gist options
  • Select an option

  • Save mthalman/2de08d4c56ddec13091eeffb438689e5 to your computer and use it in GitHub Desktop.

Select an option

Save mthalman/2de08d4c56ddec13091eeffb438689e5 to your computer and use it in GitHub Desktop.
Skip tests for empty theory data
// 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
{
}
}
// 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