Maven打包test报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin
Posted dingwen_blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Maven打包test报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin相关的知识,希望对你有一定的参考价值。
问题描述:
在
SpringBoot
项目中使用maven
打包在test
阶段出现了以上错误。网上查询的解决方案都是跳过测试这个生命周期的,但是这个其实是跳过了测试这个阶段,存在一定的安全隐患。类似这种解决方案:mvn clean package -Dmaven.test.skip=true
解决方案:
仔细检查发现是自己编写的测试方法不符合要求导致的。注。意注释部分的代码,不符合单元测试无参数的要求。
package com.dingwen.sprboojwtstu;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.dingwen.sprboojwtstu.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
@SpringBootTest
@Slf4j
class SpringbootJwtStudyApplicationTests {
public static final String SECRET_KEY = "!QAZ@WSX";
@Test
void contextLoads() {
}
/**
* jwt创建测试
*/
@Test
void jwtCreateTest() {
// 当前时间 add 60 秒
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 60);
// 模拟用户
UserEntity userEntity = UserEntity.builder()
.username("dingwen")
.password("123456")
.permissionList(Arrays.asList("admin", "developer"))
.build();
Map<String, Object> payload = new HashMap<>();
payload.put("username", userEntity.getUsername());
payload.put("password", userEntity.getPassword());
payload.put("permissionList", userEntity.getPermissionList());
// 生成令牌
String token = JWT.create()
// .withHeader() 执行加密类型 & 令牌类型: 默认即可
.withClaim("payload", payload) // 负载信息
.withExpiresAt(calendar.getTime()) // 过期时间
.sign(Algorithm.HMAC256(SECRET_KEY)); // 加密算法(签名)
log.info("生成的token为:{}", token);
// jwtVerifierTest(token);
}
/**
* jwt匹配测试
*/
/* @Test
void jwtVerifierTest(String token) {
JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(SECRET_KEY)).build();
DecodedJWT decodedJWT = jwtVerifier.verify(token);
log.info("header:{}", decodedJWT.getHeader());
log.info("payload:{}", decodedJWT.getPayload());
log.info("expiresAt:{}",decodedJWT.getExpiresAt());
Map<String, Object> payload = decodedJWT.getClaim("payload").asMap();
BiConsumer<String, Object> biConsumerPrint = (k, v) -> log.info("{}:{}", k, v);
payload.forEach(biConsumerPrint);
}*/
}
以上是关于Maven打包test报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin的主要内容,如果未能解决你的问题,请参考以下文章
git 打包报错:Maven Build时提示:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4
Maven项目启动报错:Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContex
Spring boot打包报错:Failed to execute goal org.apache.
maven打包出错: Failed to clean project: Failed to delete
maven打包工程出现错误 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test(示例代码
maven打包错误: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources(代码