0
如果我有,我想檢查方法,出於某種原因,我想測試用例在2個獨立的情況下,拆分,我會喜歡這樣做:Nsubstitute Returns在其他測試用例中未被覆蓋?
[Test]
public void EditCustomerShouldReturnExceptionWhenCustomerIsNotCreated()
{
var c = new CustomerViewModel();
_customerRepositoryMock.Update(Arg.Any<Customer>()).Returns(x => { throw new Exception(); });
Assert.Throws<Exception>(() => _customerService.EditCustomer(c));
}
[Test]
public void EditCustomerShouldReturnTrueWhenCustomerIsCreated()
{
var c = new CustomerViewModel();
_customerRepositoryMock.Update(Arg.Any<Customer>()).Returns(true);
Assert.IsTrue(_customerService.EditCustomer(c));
}
但這裏的問題是,當第一測試用例被傳遞.Update返回值是一個異常,所以當第二個測試用例想獲得返回值時,它也會得到新的Exception();作爲回報價值?爲什麼會發生?我如何覆蓋同一方法的返回值?
thx很多,定義局部變量解決了我的問題 – Timsen 2015-04-06 13:41:27