Hi.
I have some tests that are in MSTest and use data rows. this causes NCrunch to tell me to switch to dynamic analysis mode. But when I do that the projects fail to build under ncrunch and I get this exception:
An error occurred while analysing this project after it was built: System.InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.extractDynamicDataSourceFromMethodAttribute(ReflectedType fixtureType, ReflectedAttribute reflectedAttribute)
at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.<>c__DisplayClass5_0.<FindFrameworkTestsInAssembly>b__1()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Common.PerformanceTracking.PerfTracker.TryTrackActivity(String name, Action activity)
at nCrunch.Module.MSTest.Integration.MSTestDynamicDiscoverer.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.TestFinder..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, DescribedTestFrameworkDiscoverer[] describedDiscoverers, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker, TaskLogId taskLogId)
This seems to happen if I have tests which are defined like:
[DataTestMethod]
[DynamicData(nameof(TestData))]
where TestData is a method that looks like this:
public static IEnumerable<object[]> TestData => new[] {
new object[] {...test data here...}
and I have tests defined like this:
[DataTestMethod]
[MyTestData]
where MyTestData is an attribute like this:
[AttributeUsage(AttributeTargets.Method)]
public class MyTestData : Attribute, ITestDataSource {
/// <summary>
/// Called by the MSTest Framework to deliver arguments to a test
/// </summary>
/// <param name="methodInfo">The<see cref="MethodInfo"/> of the calling test</param>
/// <returns>A list of object arguments</returns>
public IEnumerable<object[]> GetData(MethodInfo methodInfo) {
yield return new object[] {
...test data here...
}
};
}
/// <summary>
/// Returns the Displayname of the test. MUST BE UNIQUE
/// </summary>
/// <param name="methodInfo">The<see cref="MethodInfo"/> of the calling test</param>
/// <param name="data">The data returned by <see cref="GetData(MethodInfo)"/></param>
/// <returns>A <see cref="String"/></returns>
public string GetDisplayName(MethodInfo methodInfo, object[] data) {
if (data is not null) {
return nameof(MyTestData );
}
return null;
}
}
if I remove both of these tests then things seem to work ok, but if I leave either in, then ncrunch seems to be unable to build the project and find the tests
Any ideas what I can do to allow these tests to work with NCrunch?