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

View File

@ -40,8 +40,10 @@ class HealthControllerTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.name").value("Jenkins Demo Application")) .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("$.version").value("1.0.0"))
.andExpect(jsonPath("$.java.version").exists()); .andExpect(jsonPath("$['java.version']").exists())
.andExpect(jsonPath("$['spring.profiles.active']").exists());
} }
@Test @Test