Build/Test Issues

MsTestv2 - TestMethod with DataRow - Empty Array - Causes compiler errors in NCrunch

Started by UppSol on 1,936 views

Hi,
I also submitted a bug report (Using VS 2022 RC), so hopefully you have enough information to reproduce this issue on your side:


I want to test a method of a class that accepts a params enum array (params ScopeTypes[] scopeTypes).

As soon as I add this line to my test([DataRow(new ScopeTypes[0])]), NCrunch can no longer build the test assembly (I'm using the latest version of NCrunch (4.10.0.6), this happens in VS 2022 RC and VS 2019 latest version.

Here a very simple sample:

 public enum ScopeTypes
    {
        Profitcenter,
        ProductGroup
    }

[TestClass]
    public class Behaviour
    {
        [TestMethod]
        [DataRow(null)]
        [DataRow(new ScopeTypes[0])] // !! THIS CAUSES THE PROBLEM !!
        public void DoSomething_Should_Accept_ParamsArray(ScopeTypes[] scopeTypes)
        {
            //arrange
            ClassUnderTest classUnder = new ClassUnderTest();

            //act
            classUnder.DoSomething(scopeTypes);
            
            //assert
            Assert.IsTrue(true);
        }
    }


Working without the line:
[TestClass]
    public class Behaviour
    {
        [TestMethod]
        [DataRow(null)]
        public void DoSomething_Should_Accept_ParamsArray(ScopeTypes[] scopeTypes)
        {
            //arrange
            ClassUnderTest classUnder = new ClassUnderTest();

            //act
            classUnder.DoSomething(scopeTypes);
            
            //assert
            Assert.IsTrue(true);
        }
    }

Edited

Hi, thanks for sharing this problem. I've reproduced it exactly as described.

The problem is in NCrunch's MSTest static analyser. It can't handle the Enum types. I'm going to take a closer look at this to see what kind of support can be provided. As the static analyser doesn't work the same as a dynamic runtime environment, I can't promise at this stage that we'll be able to support this use case... but at the very least, I think it would be good if we didn't just blow up with an internal exception.

Switching your 'Framework Utilisation Type for MSTest' to DynamicAnalysis should work around the problem.
Remco wrote:Hi, thanks for sharing this problem. I've reproduced it exactly as described.

The problem is in NCrunch's MSTest static analyser. It can't handle the Enum types. I'm going to take a closer look at this to see what kind of support can be provided. As the static analyser doesn't work the same as a dynamic runtime environment, I can't promise at this stage that we'll be able to support this use case... but at the very least, I think it would be good if we didn't just blow up with an internal exception.

Switching your 'Framework Utilisation Type for MSTest' to DynamicAnalysis should work around the problem.


Thx for the fast reply!
For now we will switch to 'DynamicAnalysis'

br

Post a reply

Log in to reply.