当进行单元测试时,什么是模拟涉及源,流和接收器的Akka Streams调用的最佳方法?
例如,takeWhile
功能:
takeWhile
def takeWhile(p: Out => Boolean): Repr[Out]
是特征中的一个特征:
Repr
如果被测对象调用类似的内容: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
的源代码,它是内部的,不应从它派生...这会影响对它的嘲笑吗?
对于使用Akka Streams组件的基本测试,您无需进行任何模拟。而是使用FlowOps
。要获取灵感,请查看warns。这是来自testkit的示例:
tests in the Akka repository