【发布时间】:2026-01-27 07:45:02
【问题描述】:
假设我们想做牛排。
Public class Restaurant{
public void MakeSteak(Steak rawSteak) {
this.KitchenServices.AddSeasoning(rawSteak);
this.KitchenServices.Grill(rawSteak);
}
}
在单元测试中,我可以确保给定一块生牛排,我们同时对其进行调味和烧烤:
public void MakeSteakTest() {
var rawSteak = new Steak();
this.restaurant.MakeSteak(rawSteak);
this.KitchenServices.Verify(x => x.AddSeasoning(rawSteak) , Times.Once);
this.KitchenServices.Verify(x => x.Grill(rawSteak) , Times.Once);
}
我的问题是,我们是否应该进行测试以确保牛排在烤完后没有调味?如果是,如何?
【问题讨论】:
标签: c# unit-testing nunit