java springboot 初体验 (十)对接ut
- 上一篇
- java springboot 初体验 (九)对接http请求
- https://www.cnblogs.com/zwjvzwj/p/16614205.html
- pom文件添加依赖包
-
<!-- 自动查找主类 用于打包 和 jacoco的配置 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> -
-
- 在test中添加测试文件
-
package com.zwj.zwjproject.testController.outer; import com.zwj.zwjproject.ZwjProjectApplication; import com.zwj.zwjproject.controller.outer.TestOuterController; import com.zwj.zwjproject.dto.TestApiReqDTO; import com.zwj.zwjproject.dto.TestApiRespDTO; import com.zwj.zwjproject.result.RespEntity; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; /** * @ClassName: testOuterController * @Author zhangwujie * @Date 2022/8/23 3:12 下午 * @Description: */ @SpringBootTest(classes = ZwjProjectApplication.class) public class TestTestOuterController { @Resource private TestOuterController testOuterController; @Test public void testtestApi() { try { String s = testOuterController.testApi(); assert "success".equals(s); } catch (Exception e) { e.printStackTrace(); } } }
-
- 运行jacoco
- 主要用来生成单元测试报告
- 直接点击idea的install或者使用命令"
mvn install" 、"mvn jacoco:report" //生成报告
- 点击test运行单元测试
- 下一篇
- java springboot 初体验 (十一)对接mysql
- https://www.cnblogs.com/zwjvzwj/p/16620045.html
本文来自博客园,作者:zwjvzwj,转载请注明原文链接:https://www.cnblogs.com/zwjvzwj/p/16616151.html