Arquillian spring扩展javaconfig正在初始化每个测试的上下文

时间:2016-10-19 07:08:25

标签: java spring junit jboss-arquillian

我正在尝试使用Arquillian测试一些休息接口。 我有一个班级

@RunWith(Arquillian.class)
@SpringAnnotationConfiguration(classes = PersistenceTestConfig.class)
public class RestTest{...}

在这篇文章中,我现在有一个部署方法和几个测试。 所有测试都共享部署,但为每个测试初始化​​上下文 测试

我尝试过这个@ContextLifeCycle(ContextLifeCycleMode.TEST_CASE)注释,但我面临同样的问题。

如何配置arquillian以对所有测试使用相同的上下文?

谢谢

编辑1:

这种情况一直发生(每次测试):

2016-10-19 15:18:46 INFO  [anonymousUser] [127.0.0.1] AnnotationConfigApplicationContext:982 - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@3c8d5c05: startup date [Wed Oct 19 15:18:46 EEST 2016]; root of context hierarchy
2016-10-19 15:18:46 INFO  [anonymousUser] [127.0.0.1] LocalContainerEntityManagerFactoryBean:551 - Closing JPA EntityManagerFactory for persistence unit 'persistenceUnit'
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AnnotationConfigApplicationContext:581 - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2c0a0685: startup date [Wed Oct 19 15:18:47 EEST 2016]; root of context hierarchy
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AutowiredAnnotationBeanPostProcessor:155 - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] PostProcessorRegistrationDelegate$BeanPostProcessorChecker:328 - Bean 'persistenceTestConfig' of type [class de.awinta.licensing.server.core.config.PersistenceTestConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:114 - [PERSISTENCE CONFIG] - Initialize Spring Bean: exceptionTranslation
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:89 - [PERSISTENCE CONFIG] - Initialize Spring Bean: entityManagerFactory
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractJPAConfig:61 - [PERSISTENCE CONFIG] - Initialize Spring Bean: dataSource
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LocalContainerEntityManagerFactoryBean:334 - Building JPA container EntityManagerFactory for persistence unit 'persistenceUnit'
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LogHelper:46 - HHH000204: Processing PersistenceUnitInfo [
    name: persistenceUnit
    ...]
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] AbstractPoolBackedDataSource:522 - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 10, acquireRetryAttempts -> 10, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 3000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge7xl9j1paaqpcnkbsaf|1cb8ec46, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.h2.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge7xl9j1paaqpcnkbsaf|1cb8ec46, idleConnectionTestPeriod -> 3000, initialPoolSize -> 3, jdbcUrl -> jdbc:h2:mem:arquillian, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 1000, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] Dialect:145 - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] LobCreatorBuilder:123 - HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] ASTQueryTranslatorFactory:47 - HHH000397: Using ASTQueryTranslatorFactory
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:207 - HHH000228: Running hbm2ddl schema update
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:218 - HHH000102: Fetching database metadata
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] SchemaUpdate:230 - HHH000396: Updating schema
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] TableMetadata:65 - HHH000261: Table found: ARQUILLIAN.PUBLIC.LS_DB_UPDATE
2016-10-19 15:18:47 INFO  [anonymousUser] [127.0.0.1] TableMetadata:66 - HHH000037: Columns: [id, last_modified_time, update_file, run_date, created_time]

Arquillian网站引用:

  

以前的版本有一个共同的缺点,每个测试都在运行   使用Spring的ApplicationContext的单独实例。虽然   ApplicationContext被销毁,其所有资源都被释放   在测试执行之后,这为每个带来了额外的开销   测试。从现在开始,开发人员可以控制他是否愿意   每个测试用例只创建一个上下文或运行每个测试   具有新的“干净”环境,在某些情况下可能会很方便。通过   默认情况下,上下文只会创建一次,但很容易   通过将@ContextLifeCycle注释添加到测试用例中来更改。

我做错了什么?

0 个答案:

没有答案