Created
March 26, 2015 13:13
-
-
Save herecydev/39a652d881353e4cb6c6 to your computer and use it in GitHub Desktop.
Xunit bug when data is an array
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
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) }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To confirm, just changed the byte arrays on lines 5 and 43 to int arrays to confirm it isn't a byte serialization issue: