I'm trying to use an XUnit theory, with data supplied by a DataClass, to expand a large number of scenarious (a few hundred). However, I only see one entry in the test output. I was expecting to see each "data row" listed as a test. This appears to work in Visual Studio's test runner, but not in NCrunch.
I created a simple minimal repro to illustrate:
Code:
using System.Collections;
namespace TestProject1
{
public class Poco
{
public int Id { get; set; }
public string Name { get; set; }
/// <inheritdoc />
public override string ToString() => $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}";
}
public class DataClass : IEnumerable<object[]>
{
/// <inheritdoc />
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { new Poco { Id = 1, Name = "First" } };
yield return new object[] { new Poco { Id = 2, Name = "Second" } };
}
/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class UnitTest1
{
[Theory]
[ClassData(typeof(DataClass))]
public void Test1(Poco row) => Assert.NotNull(row);
}
}
In Visual Studio's test runner, this "discovers" as a single test, but int the Test Detail pane, I see an entry for each "row" with its individual pass/fail result.
Quote:
TestProject1.UnitTest1.Test1
Source: UnitTest1.cs line 31
Test has multiple result outcomes
1 Passed
1 Failed
Results
2) TestProject1.UnitTest1.Test1(row: Id: 2, Name: Second)
Duration: 2 ms
Message:
Assert.Equal() Failure: Values differ
Expected: 2
Actual: 1
Stack Trace:
UnitTest1.Test1(Poco row) line 31
InvokeStub_UnitTest1.Test1(Object, Span`1)
MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
1) TestProject1.UnitTest1.Test1(row: Id: 1, Name: First)
Duration: 8 ms
Is there any way to get a similar result in NCrunch?