[英]SpringBoot and GitLab CI to run tests
I would like to just use GitLab CI to run test only not to deploy my app. 我想只使用GitLab CI运行测试,而不是部署我的应用程序。 I manage to assembly this
.yml
file: 我设法组装这个
.yml
文件:
image: java:8
stages:
- build
- test
build:
stage: build
script: ./gradlew build
artifacts:
paths:
- build/libs/myApp-4.0.0-SNAPSHOT.jar
unitTests:
stage: test
script:
- ./gradlew test
And in the GitLab Pipeline I get the following error: 在GitLab管道中,我收到以下错误:
ar.com.sebasira.myApp.myAppApplicationTests > contextLoads FAILED java.lang.IllegalStateException Caused by: org.springframework.beans.factory.BeanCreationException Caused by: org.springframework.beans.BeanInstantiationException Caused by: org.springframework.beans.factory.BeanCreationException Caused by: org.springframework.beans.BeanInstantiationException Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException
ar.com.sebasira.myApp.myAppApplicationTests> contextLoads FAILED java.lang.IllegalStateException引起:org.springframework.beans.factory.BeanCreationException引起:org.springframework.beans.BeanInstantiationException引起:org.springframework.beans.factory。 BeanCreationException由以下原因引起:org.springframework.beans.BeanInstantiationException由以下引起:org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException
I'm guessing this could be related to database, right? 我猜这可能与数据库有关,对吗? I need to provide that database with credentials in my Server where the runner is?
我需要在我的服务器中提供带有凭据的数据库吗?
If so, how should I do it? 如果是这样,我该怎么做? I'currently using
application.properties
file to define the connection to the DB. 我目前正在使用
application.properties
文件来定义与DB的连接。
And one more question... in the .gitlab-ci.yml
file I need to put the path to the .jar
but that filename will change everytime I update the version of my app. 还有一个问题......在
.gitlab-ci.yml
文件中,我需要将路径放到.jar
但每次更新应用程序版本时,该文件名都会更改。 Do I need to manually change it? 我需要手动更改吗?
As you are starting the whole Spring context with this test (I think it's the generated standard test from Spring Boot) with the annotations @RunWith(SpringRunner.class)
and @SpringBootTest
you have to provide a datasource. 当您使用注释
@RunWith(SpringRunner.class)
和@SpringBootTest
进行此测试(我认为是Spring Boot生成的标准测试)开始整个Spring上下文时,您必须提供数据源。 You can do one of the following: 您可以执行以下操作之一:
application.properties
in src/test/resources
(you could provide a test database on your database server as I wouldn't connect to your production database on every test) src/test/resources
中的application.properties
中指定数据库凭据(您可以在数据库服务器上提供测试数据库,因为我不会在每次测试时连接到您的生产数据库) H2
for this test H2
进行此测试 Regarding your GitlabCI question: Just use *
to match any .jar
no matter which version: - build/libs/myApp-*.jar
关于你的GitlabCI问题:只要使用
*
来匹配任何.jar
无论哪个版本: - build/libs/myApp-*.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.