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

Notification

Icon
Error

DataRow issue with MSTest 3
jschreuder
#1 Posted : Wednesday, December 21, 2022 1:03:37 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/5/2015(UTC)
Posts: 40
Location: Australia

Thanks: 12 times
Was thanked: 22 time(s) in 10 post(s)
Tried updating to the latest MSTest 3 package and ran into a build issue.

With [DataRow] tests that use params for a list of values passed into a test, eg.

Code:

[DataRow("A")]
[DataRow("A", "B")]
[DataRow("A", "B", "C")]
[DataRow("A", "B", "C", "D")]
[DataRow("A", "B", "C", "D", "E")]
[DataRow("A", "B", "C", "D", "E", "F")]
[DataTestMethod]
public void DataRowTest(params string[] letters)
{
     Assert.AreEqual(letters, letters);
}


NCrunch can no longer build the project. Error is as follows:
Quote:

NCrunch has encountered an internal error: System.Exception: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Object[]'.
at nCrunch.Module.MSTest.Integration.MSTestCilResolvedParameters..ctor(CilCustomAttribute dataRowAttribute)
at nCrunch.Module.MSTest.Integration.MSTestCilDiscoverer.createTestCases(CilMethodDefinition method, CilTypeDefinition fixture)
at nCrunch.Module.MSTest.Integration.MSTestCilDiscoverer.<FindFrameworkTestsInAssembly>b__12_0()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Module.MSTest.Integration.MSTestCilDiscoverer.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.Compiler.StaticManipulation.BuiltCilAssembly.DiscoverTests(TestFrameworkDescription[] applicableTestFrameworks, ComponentUniqueName testComponentUniqueName)
at nCrunch.Compiler.CilProcessingTasks.CilTestDiscoveryTask.ProcessTask(IBuiltAssembly builtAssembly, ComponentInstrumentationParameters instrumentationParameters, BuildOutput output)
at nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.()
at nCrunch.Compiler.CilProcessingTasks.ConcurrentCilTaskProcessor.ProcessTasks(Int32 backgroundThreadsAllowed)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentInstrumentationParameters , BuildOutput , IBackgroundTaskProcessor )
at nCrunch.Compiler.RemoteBuildRunner.PerformPostProcessingOfBuiltAssembly(ComponentInstrumentationParameters instrumentationParameters, BuildOutput output, IBackgroundTaskProcessor backgroundTaskProcessor)
at nCrunch.Core.BuildManagement.BuildEnvironment..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents, GridClientId gridClientId, IList`1 customEnvironmentVariables, IPlatformBuildExtender extender, Guid taskId, GridAddress clientAddress, Boolean extractCoverageReportStructure)


The same code builds and works fine in MSTest 2.2. My best guess is this is something related to this breaking change.
https://github.com/microsoft/testfx/pull/1332

Sidenote - there is a variant that NCrunch will build with MSTest 3, but the test cannot run under NCrunch (though it runs via VS test runner).

Code:

[DataRow(new string[] { "A" })]
[DataRow(new string[] { "A", "B" })]
[DataRow(new string[] { "A", "B", "C" })]
[DataRow(new string[] { "A", "B", "C", "D" })]
[DataRow(new string[] { "A", "B", "C", "D", "E" })]
[DataRow(new string[] { "A", "B", "C", "D", "E", "F" })]
[DataTestMethod]
public void DataRowTestArray(string[] letters)
{
    Assert.AreEqual(letters, letters);
}


This results in a failing test with message:
Quote:
Unable to transfer an Array from a statically analysed domain into a dynamic runtime domain. Please change your 'Framework utilisation type for MSTest' setting to 'UseDynamicAnalysis' to run this test.


Here's a repro solution with both of the above cases:
https://1drv.ms/u/s!ArNW31rplqplm0WV52MqdOpMOrxA?e=BLQkmw
Remco
#2 Posted : Wednesday, December 21, 2022 1:19:55 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,746

Thanks: 886 times
Was thanked: 1203 time(s) in 1123 post(s)
Thanks for sharing this issue. I believe your analysis is correct; they've changed the constructor signatures for this attribute and it's broken our static test discovery.

The workaround for this problem is to set your Framework utilisation type for MSTest to 'UseDynamicAnalysis'. This will force NCrunch to use runtime reflection to discover the tests (as opposed to statically analysing the assembly), which will allow the project to build and the tests to be discovered.

I'll include a proper fix for this problem in the next release of NCrunch.
1 user thanked Remco for this useful post.
jschreuder on 12/21/2022(UTC)
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.040 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download