我昨天开始查看 FsCheck,我正在尝试编写一个简单的测试,即 DiscountAmount 的任何实例都将始终具有负值。我的问题是,在一个测试中是否可以有多个断言。例如,这里我说创建 discountAmount 的金额加上折扣金额应该是 0。但我也说折扣金额应该小于 0。这应该是 2 次测试还是 1 次?
public class DiscountAmountTests
{
[Property()]
public void value_or_created_discountAmount_should_be_negative()
{
Arb.Register<AmountArbitrary>();
Prop.ForAll<Amount>(
v =>
{
var sut = new DiscountAmount(v);
var expectedResult = 0;
var result = v + sut;
result.Should().Be(expectedResult);
sut.Value.Should().BeLessThan(0);
})
.QuickCheckThrowOnFailure();
}
public class AmountArbitrary
{
public static Arbitrary<Amount> Amounts()
{
return Arb.Generate<decimal>().Where(x => x > 0)
.Select(x => new Amount(x))
.ToArbitrary();
}
}
}
}