我有一些基礎測試類,它們使用測試執行偵聽器爲彈簧,日誌記錄,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