我正在和一个有很多属性的类合作.例如;
public class Bib { public int PartQty { get; set; } }
现在进行单元测试;我做了xUnit测试
[Fact] public void CanGetAndSetPartQuantity() { const int expected = 3; var target = new Bib() {PartQty = expected}; Assert.Equal(expected,target.PartQty); }
解决方法
Constrained Non-determinism适合这种单元测试.这样写:
[Fact] public void CanGetAndSetPartQuantity() { const int expected = new Random().Next(); var target = new Bib() {PartQty = expected}; Assert.Equal(expected,target.PartQty); }
这确保输出正确地表示输入,无论输入是什么.