我正在尝试为我的演员编写单元测试并坚持基本的模拟。PriceAggregateActor 正在使用 akka 持久性,我不想为它传递所有的 conf 并且想完全模拟它。
这是我要测试的演员
object CommandPriceActor {
def apply() = Props(classOf[CommandPriceActor], PriceAggregateActor())
}
class CommandPriceActor(priceAggregateActorProps: Props) extends Actor with ActorLogging {
val priceAggregateActor = context.actorOf(priceAggregateActorProps, "priceAggregateActor")
所以在我的测试中,我试图做类似的事情:
class CommandPriceActorTest extends TestKit(ActorSystem("test-benefits",
ConfigFactory.parseString("""akka.loggers = ["akka.testkit.TestEventListener"] """))) with FlatSpecLike with Matchers
with BeforeAndAfterAll with Eventually{
class MockedChild extends Actor {
def receive = {
case _ => lala
}
}
val probe = TestProbe()
val commandPriceActor = TestActorRef(new CommandPriceActor(Props[MockedChild]))
我总是得到:
Caused by: java.lang.IllegalArgumentException: no matching constructor found on class CommandPriceActorTest$MockedChild for arguments []
为什么抱怨 mockedChild?它不应该采用任何构造函数参数。