[英]Mockito: Mocking method that is not yet defined but know the return type
I have a method yet to be defined, but the return type is known.我有一个方法尚未定义,但返回类型是已知的。 Is there a way I can still mock this method and test the return to match with the return type?
有没有办法我仍然可以模拟这个方法并测试返回与返回类型匹配?
def getX(a: String): Future[returnType]
when(someService.getX(a)).thenReturn(Future.successful(returnType))
If I understand you correctly, you're looking for ???如果我理解正确,您正在寻找??? .
.
You can define your method like:您可以定义您的方法,如:
def getX(a: String): Future[returnType] = ???
Then you could reference it in your tests or other code and everything would compile, but calling it will fail at runtime with NotImplementedError
thrown.然后你可以在你的测试或其他代码中引用它,一切都会编译,但在运行时调用它会失败并
NotImplementedError
。 It will also fail in tests unless you override it in mock.除非您在模拟中覆盖它,否则它也会在测试中失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.