Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

MSTest in dynamic mode causes NCrunch to error
samholder
#1 Posted : Friday, February 2, 2024 10:45:24 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/11/2012(UTC)
Posts: 94

Thanks: 28 times
Was thanked: 12 time(s) in 12 post(s)
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?
Remco
#2 Posted : Friday, February 2, 2024 11:59:12 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sharing this issue.

I'm having trouble building a sample that can produce this problem. Are you able to throw together a small sample project that you can send through to me that demonstrates it? Thanks!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.043 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download