Build/Test Issues

MSTest TestContext CancellationTokenSource null

Started by VNicholson on 1,916 views

Hi,

I updated to the most recent MSTest meta package recently and resolved a number of analyzer warnings, MSTEST0049 being one of them. The suggested fix for that warning is to leverage the TestContext.CancellationTokenSource.Token property when invoking asynchronous methods with cancellation token parameters. The test context injected by NCrunch has a null CancellationTokenSource property however preventing this from being used.

Further to this, the latest documentation from Microsoft suggests constructor injection of the test context being the recommended way of obtaining a test context. NCrunch however requires there to be a parameterless constructor defined, so this approach cannot be used either.

System.MissingMethodException: Cannot dynamically create an instance of type 'MyTests'. Reason: No parameterless constructor defined.
   at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at nCrunch.TestExecution.Reflection.Clr.ClrType.CreateInstance()
   at nCrunch.Module.MSTest.Integration.MSTestTest.tryCreateFixtureInstance()


I'm aware of the murky nature of the MSTest emulation in NCrunch, but are either of these issues something that can be addressed?

NCrunch 5.16.0.5 in Visual Studio by the way.

Edited

Hi, thanks for sharing this issue.

I'll need to make some adjustments to NCrunch's adapter to align it with these changes. Hopefully it's straightforward. I recommend staying on an earlier version of MSTest until we're back in alignment. I'll let you know when I have a build available you can try.
Would you be interested in trying the build below to see if this meets your needs better?

NCrunch_Console_5.17.0.2.msi
NCrunch_Console_5.17.0.2.zip
NCrunch_GridNodeServer_5.17.0.2.msi
NCrunch_GridNodeServer_5.17.0.2.zip
NCrunch_LicenseServer_5.17.0.2.zip
NCrunch_Rider_5.17.0.2.7z
NCrunch_Rider_5.17.0.2.zip
NCrunch_VS2010_5.17.0.2.msi
NCrunch_VS2010_5.17.0.2.zip
NCrunch_VS2012_5.17.0.2.msi
NCrunch_VS2012_5.17.0.2.zip
NCrunch_VS2013_5.17.0.2.msi
NCrunch_VS2013_5.17.0.2.zip
NCrunch_VS2015_5.17.0.2.msi
NCrunch_VS2015_5.17.0.2.msi.7z
NCrunch_VS2015_5.17.0.2.zip
NCrunch_VS2017_5.17.0.2.msi
NCrunch_VS2017_5.17.0.2.msi.7z
NCrunch_VS2017_5.17.0.2.zip
NCrunch_VS2019_5.17.0.2.msi
NCrunch_VS2019_5.17.0.2.msi.7z
NCrunch_VS2019_5.17.0.2.zip
NCrunch_VS2022_5.17.0.2.msi
NCrunch_VS2022_5.17.0.2.msi.7z
NCrunch_VS2022_5.17.0.2.zip
Remco wrote:Would you be interested in trying the build below to see if this meets your needs better?

I retested the TestContext constructor injection and property injection test cases and both worked with those new builds. Thanks so much for the insanely fast turn around.

Post a reply

Log in to reply.