【发布时间】:2019-11-18 14:58:15
【问题描述】:
我有一个案例类Employee
定义为case class Employee(.........fields.....)
我有一个方法说
def getEmployees(organization: String): Future[Seq[Employee]] = {
val result = employeeClient.getAllEmployees(organization)
// some logic on this list of Employees received from the
client and manipulate it to get finalListOfEmployees and return it
to caller of `getEmployees`//
finalListOfEmployees
//end //
}
现在我使用 scala mock 测试 getEmployees。我没有处理来自getEmployees 或来自recovering 的异常。这意味着出现在客户端方法getAllEmployees 的异常将返回给getEmployees 的调用者。
现在的问题是我们需要测试这方面吗?
我的意思是下面的测试是否增加了任何价值??
"Fail with future" in { (mockEmployeeClient.getAllEmployees_).expects("SomeOrganization").returning(Future.failed(new Exception("failed"))
getEmployees("SomeOrganization).failed.futureValue.getMessage shouldBe "failed"
}
【问题讨论】:
-
我从不喜欢模拟,因为你只是没有在这里测试任何东西。
-
你做的测试越多,覆盖的案例越多,你的应用就越好。
标签: scala unit-testing scalatest scalamock