Skip to content

DynamicData test is not passing exception objects correctly #1037

@krishnajay0310

Description

@krishnajay0310

We are using DynamicData to specify our test cases. We are creating an InvalidUpdateException object by passing custom exception message. However, the exception message being actually passed to the unit test method is “Exception of type ‘CCO.Contracts.InvalidUpdateException' was thrown.”

Steps to reproduce

        private static IEnumerable<object[]> TestData()
        {
            return new List<object[]>()
            {
            new object[] { new InvalidUpdateException("Test exception message") }
            };
        }        
        [DynamicData(nameof(TestData), DynamicDataSourceType.Method)]
        [TestMethod]
        public void ValidateExMessage(Exception ex)
        {
            Assert.AreEqual(ex?.Message, "Test exception message");
        }

Expected behavior

ex?.Message = "Test exception message"

Actual behavior

ex?.Message = "Exception of type ‘CCO.Contracts.InvalidUpdateException' was thrown"

Environment

Windows OS
Using Visual Studio 2022
Nuget package versions -

<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.0.0" />
 <PackageReference Update="MSTest.TestAdapter" Version="2.2.8" />
 <PackageReference Update="MSTest.TestFramework" Version="2.2.8" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions