Build/Test Issues

Failing tests with XUnit v4 and DateTime parameters

Started by DCasado on 21 views

Hi,

we updated to the latest version of XUnit (4.0.0) and NCrunch (5.23.0.1).

Some of our tests are now failing and they all have a DateTime parameter:


using AwesomeAssertions;

namespace NCrunchIssue
{
    public class UnitTest1
    {
        public static TheoryData<DateTime> TestDates => new() { { new DateTime(2025, 12, 31) } };

        [Theory]
        [MemberData(nameof(TestDates))]
        public void DateTest(DateTime expected)
        {
            expected.ToString("O").Should().Be("2025-12-31T00:00:00.0000000");
        }
    }
}



I can run the test successfully with VS Test explorer.
By downgrading XUnit to version 3.2.2 the test is successful in both (VS Test Explorer and NCrunch Tests).

You can find a working repro here: https://github.com/IT-CASADO/ncrunch-issue-02

Edited

Hi, thanks for sharing this.
It looks like xunit v4.0.0 has a time zone related serialization problem. Could you try upgrading your package dependency to v4.0.1 to see if that solves the problem?

Post a reply

Log in to reply.