java final class 实例化_java – 无法实例化TestExecutionListener

当我从

Eclipse中运行下面的硒测试时,我得到一系列不能在我的日志中实例化TestExecutionListener消息.

这是实际的测试.

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(classes = SeleniumConfig.class)

public final class TestWebpage {

private static final Logger LOG = Logger.getLogger(TestWebpage.class);

@Autowired

private WebDriver driver;

@Test

public void testLoadingPage() {

LOG.debug("Hello World!");

}

}

这是日志

0 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]

5 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]

6 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]

7 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]

8 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@152c95a3, org.springframework.test.context.support.DirtiesContextTestExecutionListener@22140b31]

127 [main] INFO org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@35523de0: startup date [Wed Oct 01 01:20:22 EST 2014]; root of context hierarchy

3961 [main] DEBUG org.rmb.selenium.external.TestWebpage - Hello World!

3963 [Thread-8] INFO org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@35523de0: startup date [Wed Oct 01 01:20:22 EST 2014]; root of context hierarchy

注意我使用的是Spring 4.1.0.RELEASE.

一个解决方案,三个额外的依赖

我在answer to a previous question中注意到了添加@WebAppConfiguration的建议

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(classes = SeleniumConfig.class)

@WebAppConfiguration

public final class TestWebpage {

那我在我的pom.xml中需要三个额外的依赖来支持:

javax.servlet-api

spring-jdbc

spring-web

为什么我根本不使用JDBC,或者使用spring-web / servlet的任何东西,都需要这些额外的东西 – 这只是我自己配置​​的一个硒测试.

有更简单的方法吗?我错过了更大的东西吗?

配置类

这是我配置我的测试的类.

public final class SeleniumConfig {

@Bean

public String baseUrl() {

return "http://localhost:8888/";

}

@Bean

public WebDriver driver() {

return new CloseableFirefoxDriver();

}

class CloseableFirefoxDriver extends FirefoxDriver implements DisposableBean {

public void destroy() throws Exception {

quit();

}

}

}

POM

我的pom.xml(在我添加额外的依赖项之前).

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

WebAppWithSeleniumTest

WebAppWithSeleniumTest

war

0.0.1-SNAPSHOT

WebAppWithSeleniumTest Maven Webapp

http://maven.apache.org

junit

junit

4.11

log4j

log4j

1.2.16

org.seleniumhq.selenium

selenium-java

2.43.1

org.springframework

spring-test

${spring.version}

test

org.springframework

spring-context

${spring.version}

WebAppWithSeleniumTest

src/main/resources

${basedir}/target/classes

log4j.properties

Web App with Selenium Tests - a base

4.1.0.RELEASE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值