大家好
授人以鱼不如授人以渔
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.

点击test如下

然后就停止编译了
先看一下maven的打包日志,选择项目名字,可以查看最全的日志




如果知道问题点的话的话可以注test(甚至解决这个问题都行,但我觉得没必要。如果项目很多人合作,test里面有大量的代码,而且都不是必要的代码),代码太多可以注释掉整个文件的代码
在pom.xml文件添加下面的代码,maven打包的时候忽略测试的失败(也可以这样做,但不是最优的解决方案)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-surefire-pluginartifactId>
<configuration>
<testFailureIgnore>truetestFailureIgnore>
configuration>
plugin>
plugins>
build>
idea工具可以选择maven选项功能,选中小闪电,下面的test就会变为灰色,意思是打包的时候跳过test

maven命令为
-DskipTests=true
再次打包就没问题了
