[英]Does Mockito support @Any @Inject with CDI's Instance<> interface?
I have a class containing the following code: 我有一个包含以下代码的类:
@Inject
@Any
private Instance<SomeInterface> SomeInterfaces;
This allows me to then iterate over all implementations of that interface. 这允许我迭代该接口的所有实现。 Now, I want to test this, so I declare some
@Mock
's of those interfaces, and want to @InjectMocks
them into my unit under test. 现在,我想测试一下,所以我声明了一些
@Mock
的接口,并希望@InjectMocks
它们放入我测试的单元中。 But that fails. 但那失败了。
Is it possible to do something like that nicely, or do I have to create a @Mock
for Instance<SomeInterface>
有可能做得很好,或者我必须创建一个
@Mock
for Instance<SomeInterface>
Mockito can do the full job for unit tests. Mockito可以完成单元测试的全部工作。 Here you want to test how you code integrates with the CDI context => you need an instance of the CDI context that you use.
在这里,您要测试代码如何与CDI上下文集成=>您需要一个您使用的CDI上下文的实例。 Of course, you could ask Mockito to inject some mocks, but that way you will test Mockito internal injection system and not your CDI context.
当然,你可以要求Mockito注入一些嘲讽,但这样你就会测试Mockito内部注射系统,而不是你的CDI环境。 And Mockito warns you:
Mockito警告你:
Mockito is not an dependency injection framework, don't expect this shorthand utility to inject a complex graph of objects be it mocks/spies or real objects.
Mockito不是一个依赖注入框架,不要指望这个简写实用程序可以注入一个复杂的对象图形,无论是模拟/间谍还是真实对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.