【发布时间】:2016-04-27 07:21:29
【问题描述】:
我正在使用 MockitoSugar 编写单元测试用例。
这是我的示例代码:
class EmployeeRepo {
def addEmplyees(emp:Employee): Long = {
//logic
val res1 = sendReport
val res2 = sendNotification
//logic
}
def sendReport:Boolean={
//logic
}
def sendNotification:Unit={
//logic
}
}
示例测试用例:
class TestEmployeeRepo extends WordSpec with MockitoSugar with ScalaFutures {
"TestEmployeeRepo" must {
"add employee" in {
//mock statements
val result = MockEmployeeRepo.addEmplyees(emp)
//assert statements
}
}
}
object MockEmployeeRepo extends EmployeeRepo {
override def sendReport:Boolean = true
override def sendNotification:Unit = //needs unit
}
在上面的代码中,我试图用必要的模拟来测试addEmployee 方法。所以在覆盖 sendNotificationwhich 实际上返回 Unit 时,我不确定我应该如何返回 Unit。
我尝试了这两种方法:
override def sendNotification:Unit = println("")
override def sendNotification:Unit = Unit
工作正常,但请建议我正确的方法以及//needs unit 应该有什么。提前致谢。
【问题讨论】:
标签: scala unit-testing mockito