Testing with empty string using DataRow in MsTestV2

Viewed 365

I'm trying to build a data driven test that will validate the behaviour of a method when receiving either an empty string or a null value. What I did is add to DataRow attributes but unless I add the display name, they are considered as a single row. With the display name, my test is called 2 times but both calls set the value to null. Is it possible to test for empty string with DataTestMethod?

Here is my code

[DataTestMethod]
[
    DataRow("", DisplayName ="Empty"),
    DataRow(null, DisplayName ="Null")
]
public void MyTest(string value)
{
    //Arrange
    //Act
    var result= new MyObject(value);

    //Assert
    Assert.IsNull(result);
}

Edit I also tested with DynamicData and the result is identical

private static IEnumerable<Object[]> EmptyOrNullStrings { get; } = new Object[][] { 
        new Object[] { string.Empty }, 
        new Object[] { null } };
[DataTestMethod]
[DynamicData(nameof(EmptyOrNullStrings), DynamicDataSourceType.Property)]
public void ZoneComplementaireVide_IdEnveloppeNull(string zoneComplementaire){...}
1 Answers
Related