gbe*_*ley 30 junit spring intellij-idea
我有一些基本测试类,它们使用测试执行监听器为spring,logging,jndi等设置常用配置,然后由子类继承.这样做是为了测试可以只运行代码而不必担心在运行测试代码之前获取jndi和日志服务.
使用intellij并从项目库调用"运行所有测试",IDE尝试将基本测试类作为单元测试运行,并为我提供"无可运行方法"错误.
我知道我可以在基类中放置一个空的runnable方法,但我希望有一个人有更好的主意.
Base类是:
@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());
}
Run Code Online (Sandbox Code Playgroud)
错误:
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)
Run Code Online (Sandbox Code Playgroud)
我遇到过同样的问题。我在没有测试方法的情况下进行测试。
@Test
public void setupTest() {
}
Run Code Online (Sandbox Code Playgroud)
以上方法解决了问题。
| 归档时间: |
|
| 查看次数: |
25250 次 |
| 最近记录: |