我不能MockitoSugar
和AsyncFunSuite
一起使用。总之:
此示例有效(取自 Scalatest 文档(
class AddSuite extends AsyncFunSuite {
def addSoon(addends: Int*): Future[Int] = Future { addends.sum }
test("addSoon will eventually compute a sum of passed Ints") {
val futureSum: Future[Int] = addSoon(1, 2)
futureSum map { sum => assert(sum == 3) }
}
}
但是这个例子没有(因为它有MockitoSugar
class AddSuite extends AsyncFunSuite with MockitoSugar {
def addSoon(addends: Int*): Future[Int] = Future { addends.sum }
test("addSoon will eventually compute a sum of passed Ints") {
val futureSum: Future[Int] = addSoon(1, 2)
futureSum map { sum => assert(sum == 3) }
}
}
两个编译都报告了后者的零测试,而前者报告了一个测试。这发生在IntelliJ和sbt上。为什么这不起作用?我该如何解决这个问题?
我正在使用:
- 斯卡拉 2.12
- SCA最新 3.1.1
- 模拟核心 3.3.3
- 莫基托-斯卡拉 1.13.10
没关系,在查看了mockito-scala代码库后才弄清楚。我应该使用AsyncMockitoSugar
而不是MockitoSugar
.所以它应该是:
class AddSuite extends AsyncFunSuite with AsyncMockitoSugar {
def addSoon(addends: Int*): Future[Int] = Future { addends.sum }
test("addSoon will eventually compute a sum of passed Ints") {
val futureSum: Future[Int] = addSoon(1, 2)
futureSum map { sum => assert(sum == 3) }
}
}