You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that MSTest will, under certain conditions, clandestinely change the runtime type of test data provided to parameterized tests. See repro code below.
type should be System.Double in all 4 cases, and all tests should pass with no error.
Actual behavior
type is System.Int32 in the two cases where 1d is specified as the double value, and System.Decimal in the two cases where 1.1 is specified as the value. Therefore the unboxing fails in all 4 cases.
Additional context
VS 2022
.NET 8
MSTest.TestAdapter 3.7.3
MSTest.TestFramework 3.7.3
The text was updated successfully, but these errors were encountered:
scharnyw
changed the title
Framework unexpectedly changes the runtime type of test data provided to parameterized tests
MSTest unexpectedly changes the runtime type of test data provided to parameterized tests
Feb 6, 2025
This is unfortunately a known behavior. The problem is that we need to serialize the test arguments in discovery, and deserialize back when executing. Currently, there is no perfect serialization mechanism that we can use.
The only workaround is to not expand the test during discovery, and do so only during execution. You can do that in two ways:
Apply that globally for all tests in your assembly by adding [assembly: TestDataSourceOptions(TestDataSourceUnfoldingStrategy.Fold)]
Side note: We recommend that you move from DataTestMethod to TestMethod. They are equivalent and are currently interchangeable. We may deprecate DataTestMethod in the future.
Note that "Folding" means that the data source isn't expanded during discovery. This affects how the test is shown in Test Explorer, and also affects the TRX format in that you will see multiple results associated to a single test.
Describe the bug
It appears that MSTest will, under certain conditions, clandestinely change the runtime type of test data provided to parameterized tests. See repro code below.
Steps To Reproduce
Run the following tests:
Expected behavior
type
should beSystem.Double
in all 4 cases, and all tests should pass with no error.Actual behavior
type
isSystem.Int32
in the two cases where1d
is specified as the double value, andSystem.Decimal
in the two cases where1.1
is specified as the value. Therefore the unboxing fails in all 4 cases.Additional context
VS 2022
.NET 8
MSTest.TestAdapter 3.7.3
MSTest.TestFramework 3.7.3
The text was updated successfully, but these errors were encountered: