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

Notification

Icon
Error

MsTestv2 - TestMethod with DataRow - Empty Array - Causes compiler errors in NCrunch
UppSol
#1 Posted : Monday, October 18, 2021 7:41:12 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/21/2019(UTC)
Posts: 39
Location: Austria

Thanks: 30 times
Was thanked: 7 time(s) in 7 post(s)
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:

Code:
 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);
        }
    }
Remco
#2 Posted : Monday, October 18, 2021 8:04:08 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 929 times
Was thanked: 1256 time(s) in 1169 post(s)
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.
UppSol
#3 Posted : Monday, October 18, 2021 8:09:58 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/21/2019(UTC)
Posts: 39
Location: Austria

Thanks: 30 times
Was thanked: 7 time(s) in 7 post(s)
Remco;15717 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
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.029 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download