首页 > 解决方案 > 在jenkins中构建项目时,为junit测试用例的Assert之类的符号找不到符号

问题描述

我的 Maven Spring Boot 项目中有 Junit 测试用例。在构建项目时,找不到诸如 Before、Assert 之类的 junit 符号。可能是什么问题?

部分日志如下,

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/svn repo/delivery-management- 
   service/src/test/java/com/poc/delivery/DeliveryControllerNewTest.java:[4,24] cannot find symbol
      symbol:   class Assert
      location: package org.junit
[ERROR] /C:/svn repo/delivery-management- 
    service/src/test/java/com/poc/delivery/DeliveryControllerNewTest.java:[11,17] cannot find symbol
    symbol:   class Before
    location: package org.junit

标签: spring-bootjenkinsjunitjunit5

解决方案


很可能您没有为Assert静态Before方法声明导入

    import org.junit.Assert;
    ... 
    Assert.assertEquals(...)

    import org.junit.Before;

您还可以运行mvn install以确保所有依赖项都在本地下载


推荐阅读