gpt4 book ai didi

spring - 基本测试类没有可运行方法错误

转载 作者:IT老高 更新时间:2023-10-28 13:45:27 25 4
gpt4 key购买 nike

我有一些基础测试类,它们使用测试执行监听器为 spring、logging、jndi 等设置通用配置,然后由子类继承。这样做是为了让测试可以只运行代码,而不必担心在能够运行测试代码之前获得 jndi 和日志服务。

使用 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)

最佳答案

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

关于spring - 基本测试类没有可运行方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/977017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com