fix: fix HealthControllerTest JSON path and update JaCoCo plugin usage

This commit is contained in:
wangtianqi 2025-06-23 21:38:04 +08:00
parent 22d7087d1f
commit 9c995305b4
2 changed files with 11 additions and 11 deletions

18
Jenkinsfile vendored
View File

@ -80,8 +80,7 @@ pipeline {
steps {
echo '🧪 运行单元测试...'
sh "mvn test"
}
post {
} post {
always {
script {
// 发布测试结果
@ -89,14 +88,13 @@ pipeline {
publishTestResults testResultsPattern: 'target/surefire-reports/*.xml'
}
// 发布代码覆盖率报告
if (fileExists('target/jacoco.exec')) {
step([$class: 'JacocoPublisher',
execPattern: 'target/jacoco.exec',
classPattern: 'target/classes',
sourcePattern: 'src/main/java',
exclusionPattern: '**/*Test*.class'
])
// 发布代码覆盖率报告 - 使用新语法
if (fileExists('target/site/jacoco/jacoco.xml')) {
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')], sourceFileResolver: sourceFiles('STORE_LAST_BUILD')
} else if (fileExists('target/jacoco.exec')) {
echo '⚠️ 发现jacoco.exec文件但推荐使用XML格式的覆盖率报告'
} else {
echo '⚠️ 未找到JaCoCo覆盖率报告文件'
}
}
}

View File

@ -40,8 +40,10 @@ class HealthControllerTest {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.name").value("Jenkins Demo Application"))
.andExpect(jsonPath("$.description").value("Spring Boot 3 应用程序用于Jenkins CI/CD流程演示"))
.andExpect(jsonPath("$.version").value("1.0.0"))
.andExpect(jsonPath("$.java.version").exists());
.andExpect(jsonPath("$['java.version']").exists())
.andExpect(jsonPath("$['spring.profiles.active']").exists());
}
@Test