AgentSkillsCN

test-execution

提供使用 JaCoCo 运行测试、分析结果并衡量代码覆盖率的指南。适用于执行测试套件,或设置 CI 测试阶段时使用。

SKILL.md
--- frontmatter
name: test-execution
description: Guide for running tests, analyzing results, and measuring code coverage with JaCoCo. Use when executing test suites or setting up CI test stages.

Test Execution and Validation

Maven Commands

bash
mvn test                    # Unit tests only
mvn verify                  # Unit + integration tests
mvn test -Dtest=ClassName   # Specific class
mvn test -Dtest=Class#method # Specific method
mvn package -DskipTests     # Build without tests

JaCoCo Coverage Setup

xml
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.11</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>
bash
mvn clean test jacoco:report   # Generate report at target/site/jacoco/index.html

Coverage Goals

ComponentMinimum
Business Logic90%
Data Models95%
I/O Operations80%
Utilities70%

Analyzing Failures

  1. Check target/surefire-reports/TEST-*.txt for details
  2. Look for expected:<X> but was:<Y> in assertion errors
  3. Re-run specific test: mvn test -Dtest=Class#method

Common Issues

ProblemFix
"Tests Run: 0"Class name must end with Test
NoClassDefFoundErrorMissing test dependency in pom.xml
Flaky testsUse @BeforeEach to reset state