我正在尝试模拟将数据插入数据库的方法。但是,当我尝试模拟该方法时,它仍然被调用。我不知道为什么。这是我的测试:
//val mockDAO = mock[DAO]
val mockDAO = spy(new DAO)
val transObj = TransactionDataObj(-1, 1, 1, 9, 9, DateTime.now(), DateTime.now(), 99, 9969, 3)
val additionalObj = AdditionalTransData(Some(90), Some(91), Some(92), Some(93), Some(94: Long))
//stub(mockDAO.addTransaction(transObj, additionalObj)).toReturn(transObj)
doReturn(transObj).when(mockDAO).addTransaction(transObj, additionalObj)
//when(mockDAO.addTransaction(transObj, additionalObj)).thenReturn(transObj)
"ControllerActor" must {
"create nameless actor when a duplicate arises for the AdderActor" in {
val controller = system.actorOf(Props[Controller])
val msg = Add(transObj, additionalObj)
controller.tell(msg, testActor)
expectMsg(true)
}
正如你所看到的,我尝试了各种各样的组合。据此website doReturn不会调用原始方法,但确实如此。对我做错了什么的想法?