Rank: Member
Groups: Registered
Joined: 6/25/2015(UTC) Posts: 15 Location: United Kingdom
Thanks: 2 times Was thanked: 3 time(s) in 3 post(s)
|
In Xunit2, it appears that parameterised generic tests aren't displaying in the UI correctly. From the following code, I would expect NCrunch to display six tests, but it actually says that there are five. (This may partly answer a previous query that I had). Code:
public class Test
{
[Theory, InlineData(true, "True"), InlineData(false, "False")]
public void SomeTest_ShouldShowAsTwoTests(bool value, string example)
{
Assert.Equal(value.ToString(), example);
}
[Theory, ClassData(typeof(ExampleData))]
public void SomeOtherTest_ShouldShowAsTwoTests(bool value, string example)
{
Assert.Equal(value.ToString(), example);
}
[Theory, ClassData(typeof(MoreExampleData))]
public void AnotherTest_ShouldShowAsTwoTests<TValue>(TValue value, string example)
where TValue : IComplexType
{
Assert.Equal(value.SomeValue.ToString(), example);
}
private class ExampleData : IEnumerable<object[]>
{
private readonly List<object[]> _data = new List<object[]>();
public ExampleData()
{
_data.Add(new object[] {false, "false"});
_data.Add(new object[] {true, "true"});
}
public IEnumerator<object[]> GetEnumerator()
{
return _data.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
private class MoreExampleData : IEnumerable<object[]>
{
private readonly List<object[]> _data = new List<object[]>();
public MoreExampleData()
{
_data.Add(new object[] { new ComplexType { SomeValue = true}, "true" });
_data.Add(new object[] { new ComplexType { SomeValue = false}, "false" });
}
public IEnumerator<object[]> GetEnumerator()
{
return _data.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
public interface IComplexType
{
bool SomeValue { get; set; }
}
public class ComplexType : IComplexType
{
public bool SomeValue { get; set; }
}
}
|