【发布时间】:2015-10-13 08:06:06
【问题描述】:
我有一段代码如下:
def someFunctioThatIWantToUnitTest() {
val p = Promise[Int]()
val result = getFutureInt(p)
val resultFut = result.future
// I extract the content in the resultFut and do what I want
val didSomething = resultFut.get // not able to get here with my unit test
}
getFutureInt(...) 看起来像这样:
private def getFutureInt(promise: Promise[Int]) {
blocking { // from the scala concurrent object
// here I successfully return the promise with an Int value
promise.success(2)
}
}
假设有适当的 ExecutionContexts 可用,我想测试 someFunctioThatIWantToUnitTest 方法!当我尝试调试我的单元测试时,它不允许我进入阻塞块并且我的测试返回失败。有没有办法解决这个问题?
【问题讨论】:
标签: scala unit-testing promise future