我想测试在测试方法期间是否从注入器创建了对象的实例。实现这一目标的最佳解决方案是什么?
@Test
public void testThingNotInstantiated() {
AnotherThing another = new AnotherThing();
// assert not instance of Thing created
}
答案 0 :(得分:2)
如果您只想检查Guice注入OnClick
,您可以写:
AnotherThing
如果Injector injector
@Before {
injector = Guice.createInjector(new AnotherThingModule());
}
@Test
public void testAnotherThingInstantiated() {
//act
AnotherThing another = injector.getInstance(AnotherThing.class);
//assert
assertNotNull(another);
}
是AnotherThing
并且你想测试Guice没有实例化它两次,你可以写:
@Singleton