Skip to content

Instantly share code, notes, and snippets.

@herecydev
Created March 26, 2015 13:13
Show Gist options
  • Save herecydev/39a652d881353e4cb6c6 to your computer and use it in GitHub Desktop.
Save herecydev/39a652d881353e4cb6c6 to your computer and use it in GitHub Desktop.
Xunit bug when data is an array
public class Tests
{
//Why is this not discovered?
[MyArrayTest]
public void ThisDoesntWork(byte[] bytes)
{
Xunit.Assert.True(true);
}
[MyStringTest]
public void ThisDoesWork(string bytes)
{
Xunit.Assert.True(true);
}
}
[Xunit.Sdk.XunitTestCaseDiscoverer("XunitTests.MyDiscoverer", "XunitTests")]
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)]
public class MyArrayTestAttribute : Xunit.FactAttribute { }
[Xunit.Sdk.XunitTestCaseDiscoverer("XunitTests.MyDiscoverer", "XunitTests")]
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)]
public class MyStringTestAttribute : Xunit.FactAttribute { }
public class MyDiscoverer : Xunit.Sdk.IXunitTestCaseDiscoverer
{
private readonly Xunit.Abstractions.IMessageSink _sink;
public MyDiscoverer(Xunit.Abstractions.IMessageSink sink)
{
_sink = sink;
}
public System.Collections.Generic.IEnumerable<Xunit.Sdk.IXunitTestCase> Discover(
Xunit.Abstractions.ITestFrameworkDiscoveryOptions discoveryOptions,
Xunit.Abstractions.ITestMethod testMethod,
Xunit.Abstractions.IAttributeInfo factAttribute)
{
object[] data = null;
var isAnArrayTest = testMethod.Method.GetCustomAttributes(typeof(MyArrayTestAttribute)).Any();
//simulate finding data
if(isAnArrayTest)
data = new object[] { new byte[] { 1, 2, 3 } };
else
data = new object[] { "hello world" };
return new[] { new Xunit.Sdk.XunitTestCase(_sink, Xunit.Sdk.TestMethodDisplay.Method, testMethod, data) };
}
}
@herecydev
Copy link
Author

Escalated this to the xunit github repo as an issue #376

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment