Skip to content

Test (EnableMSTestRunner) fails to execute with DynamicData of objects with property initialized with DateTime.UtcNow #5849

Open
@SymbioticKilla

Description

@SymbioticKilla

Describe the bug

When utilizing DynamicData in MSTestV3 for parameterized tests, any test method that receives objects containing a DateTime property (especially when initialized with DateTime.UtcNow) fails to execute if the true flag is set in the project's .csproj file. Tests using DynamicData with objects lacking DateTime properties, or standard [TestMethod] definitions, run without issues. This suggests an underlying serialization or processing problem within the MSTestRunner when handling DateTime values passed via DynamicData.

Steps To Reproduce

 <EnableMSTestRunner>true</EnableMSTestRunner> 
 <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
 namespace MSTestV3.Tests
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class SomeTests
    {
        public static IEnumerable<object[]> TestValuesWithDateTime
        {
            get
            {
                yield return new object[] { new SomeObject { Timestamp = DateTime.UtcNow, Name = "Test1" } };
            }
        }

        public static IEnumerable<object[]> TestValuesWithOutDateTime
        {
            get
            {
                yield return new object[] { new SomeObject { Name = "Test1" } };
            }
        }


        [TestMethod]
        [DynamicData(nameof(TestValuesWithDateTime))]
        public void TestWithDateTime(SomeObject someObject)
        {
            Assert.IsTrue(true);
        }

        [TestMethod]
        [DynamicData(nameof(TestValuesWithOutDateTime))]
        public void TestWithWithoutDateTime(SomeObject someObject)
        {
            Assert.IsTrue(true);
        }


        [TestMethod]
        public void Test1()
        {
            Assert.IsTrue(true);
        }

    }

    public class SomeObject
    {
        public DateTime? Timestamp { get; set; }

        public string Name { get; set; } = string.Empty;
    }
}

Expected behavior

All tests, including TestWithDateTime (which uses DynamicData with a DateTime property), should execute successfully when MSTestRunner is enabled. Alternatively, if DateTime values are not supported in this configuration, the test runner should provide a clear and informative warning or error message indicating the incompatibility rather than silently skipping the test.

Actual behavior

When true is active, the TestWithDateTime method fails to execute. It appears as "Skipped" or "Not Run" in the test summary, and no explicit error message is provided explaining the failure. In contrast, TestWithWithoutDateTime and Test1 execute as expected.
Image

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions