【发布时间】:2020-02-17 21:45:13
【问题描述】:
在进行单元测试时,模拟涉及 Source、Flow 和 Sink 的 Akka Streams 调用的最佳方法是什么?
例如takeWhile函数:
def takeWhile(p: Out => Boolean): Repr[Out]
其中Repr 是特征中的特征:
trait FlowOps[+Out, +Mat] {
import akka.stream.impl.Stages._
import GraphDSL.Implicits._
type Repr[+O] <: FlowOps[O, Mat] {
type Repr[+OO] = FlowOps.this.Repr[OO]
type Closed = FlowOps.this.Closed
}
如果被测对象调用类似:mySource.takeWhile( ... ).runWith( ... ) 我可能需要模拟它...
你如何计算出如何模拟出来,例如,mock[Source[Any, Any]].takeWhile(*) returns mock[?]
Source、Repr、FlowOps 和 Out 之间的交互我不清楚。
FlowOps trait warns 的源代码,它是内部的,不应从它派生...这会影响模拟它吗?
【问题讨论】:
-
为什么需要模拟流?我想从纯值/夹具创建测试流更容易。
标签: scala akka akka-stream mockito-scala