我在控制器中有一个void方法,可将数据插入本地数据库。我如何对该方法进行集成测试。
到目前为止,我已经尝试过了,但是不知道在assert中要添加什么。
[TestMethod]
public void ProcessTransactions()
{
// Arrange
_transactionController = new TransactionController(_transactionService, _mService);
// Act
_transactionController.ProcessTransactions;
// Assert
}
答案 0 :(得分:0)
您是否可以更改返回布尔值的方法?
public bool TryProcessTransactions()
{
bool wasGreatSuccess = false;
// do work
return wasGreatSuccess;
}
否则,我想您可以从数据库中检索应该插入的内容和Assert.IsEqual()
。
答案 1 :(得分:0)
您有几种选择,具体取决于您要测试的内容和测试的深度。
_transactionService
)并断言在模拟上调用了哪些方法,使用了哪些参数等。我个人做了<但是,strong>不推荐这种类型的测试。它们使您的代码具有很高的抗重构性。它并不能真正测试您的应用程序执行什么功能,而是如何执行您的应用程序,这对我来说意义不大。这个问题没有明确的答案。一切都是“取决于”的,但是我希望我对可能性有所了解。