Build/Test Issues

MSTest DataRow using Enum value doesn't work when parameter type is integer

Started by VNicholson on 2,876 views

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:

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:

[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?
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?
Remco 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.
VNicholson 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.

Post a reply

Log in to reply.