集成测试在执行mvn安装或mvn测试时失败,但不是来自Intellij,那是因为什么?

来源:爱站网时间:2021-12-02编辑:网友分享
我正在使用spring-boot开发spring-batch应用程序。当我在IntelliJ中运行它们时,所有测试均通过。但是,当我从命令行运行mvn test或mvn install时,出现一些错误,面对这些错误爱站技术小编也曾束手无策,如今有了这篇文章,小编再也不怕解决不了这个问题啦。大家快来看看吧!

问题描述


我正在使用spring-boot开发spring-batch应用程序。当我在IntelliJ中运行它们时,所有测试均通过。但是,当我从命令行运行mvn test或mvn install时,出现一些错误:

无法加载应用程序上下文

有人可以帮我弄清楚这里出了什么问题吗?

这是一个示例测试:

@SpringBootTest
@SpringBatchTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes= {BatchApplication.class})
public class SimpleBatchTest {

    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;

    @Test
    public void testMyJob() throws Exception {
       JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters();

       JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters);

       Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    }

}

application-test.yml:

spring:
  profiles:
    active: test
  datasource:
    jdbc-url: jdbc:h2:mem:db-expcoll;MODE=Oracle;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false
    username: user
    password: password
    driver-class-name: org.h2.Drive

Trace:

...
Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:955) ~[HikariCP-3.2.0.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:109) ~[HikariCP-3.2.0.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356) ~[spring-jdbc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:112) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$162efc7d.CGLIB$jpaVendorAdapter$8() ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$162efc7d$$FastClassBySpringCGLIB$$e41a9991.invoke() ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$162efc7d.jpaVendorAdapter() ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 75 common frames omitted
...

非常感谢您!

思路:


我猜您正在使用Spring Boot 2?在这种情况下,需要指定一个数据库URL。我通常在application.properties中执行此操作。您可以将其指定为spring.datasource.url=test-url

以上内容就是爱站技术频道小编为大家分享的集成测试在执行mvn安装或mvn测试时失败,但不是来自Intellij,那是因为什么?看完以上分享之后,大家知道是因为什么了吗。

上一篇:易于生成xpath的类是什么

下一篇:为什么我必须在这里以及如何使用分号?

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载