Gitlab CI gradle测试测试数据库错误

huangapple 未分类评论69阅读模式
英文:

Gitlab CI gradle test test database error

问题

以下是我的 .gitlab-ci.yml 文件内容:

image: java:8

stages:
    - build
    - test
    - deploy

build project:
  stage: build
  script:
    - ./gradlew build -x test
  artifacts:
    expire_in: 1 hour
    paths:
      - build/libs/*.jar

test project:
  stage: test
  script:
    - ./gradlew test

以下是用于测试位置的应用程序属性,位于 src/test/resources/application-test.properties 文件中:

server.port=8085
spring.application.name=Project Test

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=false
spring.jpa.show-sql=true

## Liquibase 迁移
spring.liquibase.change-log=classpath:db/migrations/db.changelog-master.xml

但流水线始终在测试阶段失败,显示以下错误:

> Task :test
 MedcareApplicationTests > contextLoads() FAILED
     java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
         Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1796
             Caused by: liquibase.exception.DatabaseException at SpringLiquibase.java:316
                 Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
                     Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
                         Caused by: java.net.ConnectException at PlainSocketImpl.java:-2

我还尝试了使用 MySQL 测试数据库,但没有成功。我无法查看报告,因为我认为报告是在容器内部生成的。我一整天都卡在这个问题上了,非常感谢任何帮助或提示。

英文:

Following is my .gitlab-ci.yml.

image: java:8

stages:
    - build
    - test
    - deploy
  
build project:
  stage: build
  script:
    - ./gradlew build -x test
  artifacts:
    expire_in: 1 hour
    paths:
      - build/libs/*.jar

test project:
  stage: test
  script:
    - ./gradlew test 

And following is my application properties for testing location in src/test/resources/application-test.properties

server.port=8085
spring.application.name=Project Test
    
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=false
spring.jpa.show-sql=true

## Liquibase migration
spring.liquibase.change-log=classpath:db/migrations/db.changelog-master.xml

But pipeline always fails on test stage with following error:

> Task :test
 MedcareApplicationTests > contextLoads() FAILED
     java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
         Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1796
             Caused by: liquibase.exception.DatabaseException at SpringLiquibase.java:316
                 Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
                     Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
                         Caused by: java.net.ConnectException at PlainSocketImpl.java:-2

I tried with Mysql test database too, but no luck.
I'm unable to see reports because it's generated inside container, I think. Stuck on these whole day, any help or hint is appreciated.

huangapple
  • 本文由 发表于 2020年4月8日 23:26:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/61104307.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定