NUnit是否支持Nullables?

时间:2016-11-24 14:08:21

标签: c# .net unit-testing nunit

我正在测试一个将值从一个对象映射到另一个对象的方法。 然而,当它变成nullables时,每次函数返回时更精确地bool?布尔变为null。

示例:

我想测试这种方法:

public Family CreateFamily(Family a, Father b)
{
    // some property mapping here
    IsEnable = true; // where IsEnable is a nullable boolean
}

现在使用这种方法:

family x = CreateFamily(para1,para2);


//the unit test is:
x.IsEnable.Should.BeTrue(); // but null was returned

但是当我没有使用NUNIT TestRunner时,条件得到满足

1 个答案:

答案 0 :(得分:1)

我相信你应该问的是Shouldly assertion framework是否处理Nullables,因为它看起来像你用于断言。我的猜测是没有。

你问过NUnit。最新版本的NUnit确实支持一些无用的内容。例如,所有以下测试都在NUnit 3.5中传递,

[Test]
public void TestNullableBooleanTrue()
{
    bool? b = true;
    Assert.That(b, Is.True);
}

[Test]
public void TestNullableBooleanFalse()
{
    bool? b = false;
    Assert.That(b, Is.False);
}

[Test]
public void TestNullableBooleanNull()
{
    bool? b = null;
    Assert.That(b, Is.Null);
}