大家好
授人以鱼不如授人以渔
maven打包为什么会出现这个错误,打包又干了些啥?
一 原因分析
我的test类,总共也没几行代码,居然会出错,我也是醉了
package cn.fox.mydemo;
import cn.fox.mydemo.domain.entity.MyUserEntity;
import cn.fox.mydemo.service.impl.MyUserServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@Slf4j
@SpringBootTest
class MyDemoApplicationTests {
@Autowired
private MyUserServiceImpl myUserServiceImpl;
@Test
public void t2() {
MyUserEntity one = myUserServiceImpl.getOne(new QueryWrapper<MyUserEntity>().lambda()
.eq(MyUserEntity::getName, "白"));
System.out.println(one.getName());
}
@Test
public void t1() {
log.info("info哈哈哈");
}
}
然后出现了这个问题
There are test failures.
Please refer to D:\fox\project\my-demo\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
二 maven打包过程
先看一下maven的打包日志,选择项目名字,可以查看最全的日志
1 首先是运行了TESTS
2 然后启动SpringBoot项目,因为我在test文件上面加了@SpringBootTest注解,不然我的serviceImlpl无法注入
3 接着注入mybatis,执行有@test注解的方法
4 代码有个逻辑错误,将空指针异常抛出来,maven编译失败
三 解决办法
1 注释掉@Test、或者整个文件都注释掉
如果知道问题点的话的话可以注test(甚至解决这个问题都行,但我觉得没必要。如果项目很多人合作,test里面有大量的代码,而且都不是必要的代码),代码太多可以注释掉整个文件的代码
2 忽略测试的失败
在pom.xml文件添加下面的代码,maven打包的时候忽略测试的失败(也可以这样做,但不是最优的解决方案)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
3 打包跳过所有test文件【建议】
idea工具可以选择maven选项功能,选中小闪电,下面的test就会变为灰色,意思是打包的时候跳过test
maven命令为
-DskipTests=true
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/116362.html