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

Notification

Icon
Error

MSTest DataRow using Enum value doesn't work when parameter type is integer
VNicholson
#1 Posted : Tuesday, May 7, 2024 11:45:55 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 24
Location: New Zealand

Thanks: 6 times
Was thanked: 3 time(s) in 3 post(s)
Hi,

I have an MSTest parameterized test where the data rows use enumeration values, but the test method uses an integer (because the test method covers multiple int-based enumerations). NCrunch can't seem to coerce the enumeration value from the data row annotation to an integer despite that being the base type of the enumeration and the Resharper and MSTest runners working fine and able to run these tests. The error reported by NCrunch is:

Quote:
Type mismatch on test parameter 1 (System.Int32 != EnumTest+TestEnum)

* NCrunch v5.6.0.1
* NCrunch has MSTest is configured to UseDynamicAnalysis
* MSTest.TestAdapter and MSTest.TestFramework are using v2.2.8
* Casting the enumeration value to an integer in the data row annotation works around the problem

Minimal reproduction shown below:

Code:
[TestClass]
public sealed class EnumTest
{
    [TestMethod]
    [DataRow(TestEnum.Value1)]
    [DataRow(TestEnum.Value2)]
    [DataRow(TestEnum.Value3)]
    [DataRow(OtherTestEnum.OtherValue1)]
    [DataRow(OtherTestEnum.OtherValue2)]
    public void ParameterisedTest(int enumerationValue)
    {
    }

    private enum TestEnum
    {
        Value1,
        Value2,
        Value3
    }

    private enum OtherTestEnum
    {
        OtherValue1,
        OtherValue2
    }
}

Is this an issue that could be addressed in NCrunch without the workarounds described above?
Remco
#2 Posted : Tuesday, May 7, 2024 11:55:38 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 935 times
Was thanked: 1261 time(s) in 1174 post(s)
Thanks for sharing this issue.

Could you confirm how you have your 'Framework Utilisation Type for MSTest' configuration value set? And whether changing it has any affect on the problem?
VNicholson
#3 Posted : Wednesday, May 8, 2024 12:01:14 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 24
Location: New Zealand

Thanks: 6 times
Was thanked: 3 time(s) in 3 post(s)
Remco;17320 wrote:
Could you confirm how you have your 'Framework Utilisation Type for MSTest' configuration value set? And whether changing it has any affect on the problem?

The "Framework utilisation type for MSTest" value is currently set to "UseDynamicAnalysis" (Inherited from global setting).

Changing it to "UseStaticAnalysis" does also fix the problem for these tests so it seems peculiar to "UseDynamicAnalysis" being enabled.
Remco
#4 Posted : Wednesday, May 8, 2024 3:49:59 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 935 times
Was thanked: 1261 time(s) in 1174 post(s)
VNicholson;17321 wrote:

Changing it to "UseStaticAnalysis" does also fix the problem for these tests so it seems peculiar to "UseDynamicAnalysis" being enabled.


Thanks. Usually it's the other way around for these sorts of tests. I'll take a look at see if I can improve on this.
1 user thanked Remco for this useful post.
VNicholson on 5/8/2024(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.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download