Skip to content

Empty string is passed as null with DataRowAttribute and DynamicData #938

Description

@bkqc

Description

When in a [DataTestMethod] that receives a string parameter, if we provide String.Empty or "" data using DataRowAttribute or DynamicDataAttribute, the received parameter is always null, not an empty string.

Steps to reproduce

Option 1

[DataRow(""), DataRow(null)]
[DataTestMethod]
public void ZoneComplementaireVide_IdEnveloppeNull(string value){
...
}

Option 2

[DataRow("", DisplayName ="Empty"), DataRow(null, DisplayName ="Null")]
[DataTestMethod]
public void ZoneComplementaireVide_IdEnveloppeNull(string value){
...
}

Option 3

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

Expected behavior

First time the test runs: value == string.Empty
Second time the test runs: value == null

Actual behavior

Options 1 and 3: The test runs only once with value == null
Option 2: Test runs twice, both times value == null

Environment

Using Visual Studio 2019 (Version 16.4.5), the project is in .NET Framework 4.5 and the Nugets are
<package id="MSTest.TestAdapter" version="2.2.5" targetFramework="net45" />
<package id="MSTest.TestFramework" version="2.2.5" targetFramework="net45" />

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions