我想只使用GitLab CI运行测试,而不是部署我的应用程序。我设法汇编这个.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
在GitLab管道中,我收到以下错误:
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
我猜这可能与数据库有关,对吗?我需要在我的服务器中提供带有凭据的数据库吗?
如果是这样,我该怎么做?我目前正在使用application.properties
文件来定义与DB的连接。
还有一个问题......在.gitlab-ci.yml
文件中,我需要将路径放到.jar
,但每次更新我的应用程序版本时,该文件名都会更改。我需要手动更改吗?
当您使用此测试启动整个Spring上下文时(我认为这是Spring Boot生成的标准测试),注释@RunWith(SpringRunner.class)
和@SpringBootTest
您必须提供数据源。您可以执行以下操作之一:
application.properties
中的src/test/resources
中指定数据库凭据(您可以在数据库服务器上提供测试数据库,因为我不会在每次测试时连接到您的生产数据库)H2
进行此测试关于你的GitlabCI问题:无论使用哪个版本,只需使用*
匹配任何.jar
:- build/libs/myApp-*.jar