Skip to content

Problems with null in DataRow #70

@codito

Description

@codito

Copied from microsoft/vstest#471 on behalf of @jmagaram

Description

Occasionally my unit tests fail to run and display a very cryptic message in the output. I've narrowed the problem down to using null values inside a DataRow. The error message is completely unhelpful and the fix is unexpected. I can't believe this is by-design.

[DataTestMethod]
[DataRow(false, "abc")]
[DataRow(true, "")]
[DataRow(true, "   ")]
[DataRow(true, null)]
public void IsStringNullOrWhitespace(bool expectedResult, string s)
{
    bool result = String.IsNullOrWhiteSpace(s);
    Assert.AreEqual(expectedResult, result);
}

The error message is Error in executing test. No result returned by extension. If using extension of TestMethodAttribute then please contact vendor.

The "fix" is to replace the last row with...

[DataRow(true, (string)null)]

When I do this, Visual Studio recommends removing the unnecessary cast. I've tried labeling the datarow parameters but can't seem to make this work.

Steps to reproduce

Try running the unit test above in the RC version of Visual Studio 2017.

Expected behavior

I expect the test to run and give me correct results. Or a much more helpful error message.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions