我有几个基本的测试类,它们使用测试执行侦听器为spring、日志记录、jndi等设置公共配置,然后由子类继承。这样做是为了测试可以只运行代码,而不必担心在能够运行测试代码之前将jndi和日志服务放在适当的位置。
使用intellij并从项目基础调用"run all test“,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-11 06:32:16
将父类设置为abstract或重命名,以使其不以Test或TestCase结尾。
发布于 2020-06-19 02:14:16
确保@Test注解导入是org.junit.Test,而不是像juniper这样的东西,我把juniper看作here的注释,这对我很有效。我想将此作为答案添加,以便其他人可以看到
发布于 2016-09-27 18:10:23
我也有同样的问题。我在没有测试方法的情况下进行测试。
@Test
public void setupTest() {
}上述方法解决了这个问题。
https://stackoverflow.com/questions/977017
复制相似问题