[英]Can I pass a jmockit mock of an interface as a constructor parameter of another object?
i'm playing around with jmockit. 我在玩jmockit。 Most of what I tried(with the help of the web) works splendid. 我尝试过的大多数内容(在网络的帮助下)都非常出色。
But it seems, like there is a problem when passing a reference to a 但是似乎在传递对a的引用时出现问题
@Mocked
SomeInterface someInterface
as a parameter to a constructor of object under test. 作为被测对象的构造函数的参数。 The test run shows, that the instance is null. 测试运行表明,该实例为空。
Any ideas? 有任何想法吗?
Much appreciated. 非常感激。
Use @Capturing
instead of @Mocked
. 使用@Capturing
而不是@Mocked
。
@Mocked
only mocks all instances of the given class and its super-classes but not the sub-classes or implementations of interfaces. @Mocked
仅@Mocked
给定类及其超类的所有实例,而不模拟接口的子类或实现。 That's what @Capturing
is for. 这就是@Capturing
目的。 (see Capturing implementation classes and instances ) (请参阅捕获实现类和实例 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.