我有一些基本测试类,它们使用测试执行侦听器为 spring、logging、jndi 等设置通用配置,然后由子类继承。这样做是为了让测试可以只运行代码,而不必担心在能够运行测试代码之前获得 jndi 和日志服务。
使用 intellij 并从项目库中调用“运行所有测试”,IDE 尝试将基测试类作为单元测试运行,并给出“无可运行方法”错误。
我知道我可以在基类中放置一个空的可运行方法,但我希望有人有更好的主意。
基类是:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:spring-jndi.xml"
})
@TestExecutionListeners({
Log4JSetupListener.class,
JndiSetupListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
public class SpringAppTestCase extends Assert implements ApplicationContextAware {
protected JndiTemplate jndiTemplate = new JndiTemplate();
@Autowired
protected JdbcTemplate jdbcTemplate;
protected ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext ac) {
this.applicationContext = ac;
}
//
// @Test
// public void doit(){
// // this would prevent blow up but
// all subclass tests would run an extra method
// }
protected Logger log = Logger.getLogger(getClass().getName());
}
错误:
java.lang.Exception: No runnable methods
at org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:32)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
at org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:76)