问题描述
我使用spring 5 + junit5。我有两个类-BarIT和FooIT。
@ExtendWith({SpringExtension.class})
@ContextConfiguration(classes = ModuleContextConfig.class)
public class FooIT {
@Test
public void foo() {
System.out.println("Foo");
}
}
@ExtendWith({SpringExtension.class})
@ContextConfiguration(classes = ModuleContextConfig.class)
public class BarIT {
@Test
public void bar() {
System.out.println("Bar");
}
}
这是我的套房:
@RunWith(JUnitPlatform.class)
@ExtendWith({SpringExtension.class})
@SelectClasses({
FooIT.class,BarIT.class
})
@IncludeClassNamePatterns(".*IT$")
public class SuiteIT {
}
我想在执行两个类中的测试后得到事件,我的意思是在FooIT.foo()和BarIT.bar()之后发生事件,但是,我不能这样做。我希望获得ContextClosedEvent,但未触发:
@Component
@Scope(value = Configurablebeanfactory.ScopE_SINGLetoN)
public class ApplicationListenerBean implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
System.out.println("Event:" + event.toString());
}
}
这是输出:
Event:org.springframework.context.event.ContextRefreshedEvent..
Event:org.springframework.test.context.event.PrepareTestInstanceEvent..
Event:org.springframework.test.context.event.BeforeTestMethodEvent..
Event:org.springframework.test.context.event.BeforeTestExecutionEvent..
Foo
Event:org.springframework.test.context.event.AfterTestExecutionEvent...
Event:org.springframework.test.context.event.AfterTestMethodEvent...
Event:org.springframework.test.context.event.AfterTestClassEvent...
Event:org.springframework.test.context.event.BeforeTestClassEvent...
Event:org.springframework.test.context.event.PrepareTestInstanceEvent...
Event:org.springframework.test.context.event.BeforeTestMethodEvent...
Event:org.springframework.test.context.event.BeforeTestExecutionEvent...
Bar
Event:org.springframework.test.context.event.AfterTestExecutionEvent...
Event:org.springframework.test.context.event.AfterTestMethodEvent...
Event:org.springframework.test.context.event.AfterTestClassEvent..
如果可能的话,有人可以说怎么做。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)