从Gitlab CI在Spring Boot Application上运行单元测试

时间:2019-05-05 09:19:02

标签: spring-boot gitlab gitlab-ci

我有一个带有maven的spring boot应用程序,用于依赖性管理。我已将此应用程序推送到Gitlab,并希望使用其CI / CD功能。我创建了一个文件.gitlab-ci.yml并添加了以下内容:

image: docker:latest
services:
  - docker:dind

stages:


- build
  - package
  - deploy

maven-build:
  image: maven:3-jdk-8
  stage: build
  script: "mvn package"

我已从this Medium post提取了此代码段。

现在,每次推送到存储库时,作业都会运行,但是测试用例将失败。我收到以下错误:

[ERROR]   DateUtilTest.getDateFromString » IllegalState Failed to load ApplicationContex...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeAnually » IllegalState Fail...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeCurrentMonth » IllegalState
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeCurrentQuarter » IllegalState
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeCurrentWeek » IllegalState ...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeCurrentYear » IllegalState ...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeDaily » IllegalState Failed...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeMonthly » IllegalState Fail...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeQuarterly » IllegalState Fa...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeSemiAnually » IllegalState ...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeSemiMonthly » IllegalState ...
[ERROR]   DateUtilTest.getDateIntervalFromDateAndIntervalTypeWeekly » IllegalState Faile...
[ERROR]   DateUtilTest.getNearestFutureDateFromCurrentDate » IllegalState Failed to load...

我不确定如何解决此IllegalState Failed to load ApplicationContext错误或原因。

我的示例测试用例如下:

@RunWith(SpringRunner.class)
@SpringBootTest
public final class DateUtilTest {

    private Calendar calendar;

    private Date date;

    private Date startDate;

    private Date endDate;

    @Before
    public void setup() {
        calendar = Calendar.getInstance();
        calendar.set(2019, 1, 11, 10, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        date = calendar.getTime();

        calendar.set(2019, 1, 11, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        startDate = calendar.getTime();

        calendar.set(2019, 1, 11, 23, 59, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        endDate = calendar.getTime();
    }

    @Test
    public void getDateIntervalFromDateAndIntervalTypeDaily() {
        DateInterval dateInterval = DateUtil.getDateIntervalFromDateAndIntervalType(IntervalType.DAILY, date);
        assertEquals(startDate, dateInterval.getStartDate());
        assertEquals(endDate, dateInterval.getEndDate());
    }
}

测试用例或.gitlab-ci.yml文件是否存在错误/缺失?

0 个答案:

没有答案