Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.4 DataRow - breaking change in conversion of double values #842

Closed
rikrak opened this issue May 28, 2021 · 2 comments
Closed

v2.2.4 DataRow - breaking change in conversion of double values #842

rikrak opened this issue May 28, 2021 · 2 comments

Comments

@rikrak
Copy link

rikrak commented May 28, 2021

Description

MSTest interprets constant double values as decimals, which is a change from previous behaviour

Steps to reproduce

Using the following Code:

using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MStest.DataRowExample
{
    [TestClass]
    public class Class1
    {
        [DataRow(1,2,3)]
        [TestMethod]
        public void DataRowTest_1(double x, double y, double expected)
        {
            // arrange
            
            // act
            var actual = x + y;

            // assert
            Assert.AreEqual(expected, actual);
        }

        [DataRow(1.1, 2.2, 3.3)]
        [TestMethod]
        public void DataRowTest_2(double x, double y, double expected)
        {
            // arrange
            
            // act
            var actual = x + y;

            // assert
            Assert.AreEqual(expected, actual);
        }

        [DataRow(1.11111111, 2.22222222, 3.33333333)]
        [TestMethod]
        public void DataRowTest_3(double x, double y, double expected)
        {
            // arrange
            
            // act
            var actual = x + y;

            // assert
            Assert.AreEqual(expected, actual);
        }

    }
 }

Expected behavior

All tests should pass (as they do with the previous version of MSTest)

Actual behavior

Tests 2 & 3 fail with:

threw exception: 
System.ArgumentException: Object of type 'System.Decimal' cannot be converted to type 'System.Double'.
    at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

Environment

  • MSTest 2.2.4
  • .NET Framework 4.8
  • Windows 10
  • VS 2019 (16.10.0)
@rikrak
Copy link
Author

rikrak commented May 28, 2021

Could this be related to #837 ?

@Haplois
Copy link
Contributor

Haplois commented May 28, 2021

Thank you for reporting this, it's a known issue - we're working on it. It's tracked here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants