【发布时间】:2014-04-08 22:44:52
【问题描述】:
我有一个包含各种类型的字段/属性等的类:
public string SomeStringData;
public int? SomeNullableIntegerData;
public SomeDataClass SomeSpecificData;
public int SomeIntegerData;
在我的部分代码中,应该只填写SomeStringData,我想明确地测试一下。我使用FluentAssertions 并拥有
actual.SomeStringData.Should().Be("Whatever");
但是如何测试,没有其他元素没有被触及并且仍然具有它们的默认值?我当然可以:
actual.SomeNullableIntegerData.Should().NotHaveValue("Must have no value.");
actual.SomeDataClass.Should().BeNull("Must have no value.");
actual.SomeNullableIntegerData.Should().Be(0, "Must have no value.");
但是,如何更清楚地表达这些项目应该具有默认值?
例如使用虚构的BeDefault 运算符:
actual.SomeNullableIntegerData.Should().BeDefault("Must have no value.");
actual.SomeDataClass.Should().BeDefault("Must have no value.");
actual.SomeNullableIntegerData.Should().BeDefault("Must have no value.");
有这样的选择吗?
【问题讨论】:
标签: c# unit-testing nunit default fluent-assertions