私は、テスト実行リスナーを使用してSpring、Logging、JNDIなどの一般的な構成を設定し、サブクラスによって継承されるいくつかの基本テストクラスを用意しています。これは、テストコードを実行できるようになる前に、jndiとロギングサービスを確保することを心配することなく、テストがコードを実行できるようにするためです。RunnableメソッドがありませんBase Testクラスからエラーが発生しました
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)
実際には上記のコードにはテストはありません....エラーメッセージが正しいようにコメントアウトしましたか? –
はい、コメント付きコード内のコメントで説明されました – gbegley