113 字
约 22 秒
1
Maven 构建 & 项目测试
无标签

Maven 构建 & 项目测试

测试框架集成

JUnit 5 配置


<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.9.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
    </plugins>
</build>

测试命令

运行所有测试

$ mvn test

运行特定测试类

$ mvn test -Dtest=UserServiceTest

跳过测试

$ mvn package -DskipTests

生成测试报告

$ mvn surefire-report:report

测试覆盖率


<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.8</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Maven 构建 & 项目测试
http://www.clxhxhhr.top/posts/2898/
作者
clxstart
发布于
2026-09-19
许可协议
CC BY-NC-SA 4.0
评论
0 条
还没有评论,先写一条吧。