首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基础测试类中没有可运行的方法错误

基础测试类中没有可运行的方法错误
EN

Stack Overflow用户
提问于 2009-06-10 17:24:21
回答 7查看 35.9K关注 0票数 35

我有几个基本的测试类,它们使用测试执行侦听器为spring、日志记录、jndi等设置公共配置,然后由子类继承。这样做是为了测试可以只运行代码,而不必担心在能够运行测试代码之前将jndi和日志服务放在适当的位置。

使用intellij并从项目基础调用"run all test“,IDE尝试将基础测试类作为单元测试运行,并给出"No runnable methods”错误。

我知道我可以在基类中放一个空的runnable方法,但我希望有人有更好的想法。

基类是:

代码语言:javascript
复制
    @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());

}

错误:

代码语言:javascript
复制
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)
EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2009-06-11 06:32:16

将父类设置为abstract或重命名,以使其不以TestTestCase结尾。

票数 82
EN

Stack Overflow用户

发布于 2020-06-19 02:14:16

确保@Test注解导入是org.junit.Test,而不是像juniper这样的东西,我把juniper看作here的注释,这对我很有效。我想将此作为答案添加,以便其他人可以看到

票数 11
EN

Stack Overflow用户

发布于 2016-09-27 18:10:23

我也有同样的问题。我在没有测试方法的情况下进行测试。

代码语言:javascript
复制
@Test
public void setupTest() {
}

上述方法解决了这个问题。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/977017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档