我有一些基础测试类,它们使用测试执行侦听器为弹簧,日志记录,jndi等设置常用配置,然后由子类继承。这样做是为了让测试可以运行代码,而无需担心在运行测试代码之前获取jndi和日志记录服务。No Runnable methods Error From Base测试类
使用intellij并从项目库中调用“运行所有测试”,IDE将尝试运行基本测试类作为单元测试,并为我提供“No runnable methods”错误。
我知道我可以在基类中放置一个空的runnable方法,但我希望有人有一个更好的主意。
基类是:
@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)
其实在上面的代码中没有测试....你已经注释掉了,所以错误信息是正确的? – 2009-06-13 03:37:27
是的,由评论代码 – gbegley 2009-06-16 15:19:55