2016-08-01 46 views
0

我需要通過聲吶使用Gradle分析代碼,我有一些奇怪的問題,我不能處理。我有以下項目結構聲吶跳過集成測試

-java 
    |-src 
    |-main 
    |-test 
    |-integration-test 

,並默認和集成測試目錄,如果我sonar.test屬性更改爲/ src目錄/集成測試聲納只分析測試目錄,但我想這兩個目錄一起分析我實際上不知道該怎麼做。下面我們從gradle.build文件獲得我的sonarqube任務屬性。

sonarqube { 
    properties { 
     property "sonar.projectName", "projectName" 
     property "sonar.projectKey", "org.sonarqube:projectName" 
     property "sonar.host.url", "http://sonar.doesntmetter" 
     property "sonar.java.coveragePlugin", "jacoco" 
     property "sonar.junit.reportsPath", "build/test-results/test" 
     property "sonar.jacoco.reportPath", "build/jacoco/test.exec" 
     property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec" 
    property "sonar.login", "admin" 
    property "sonar.password", "admin" 
    } 
} 

我注意到的是,當我運行gradle這個構建會有integrationTest.exec和/編譯/ jacoco /目錄test.exec,但如果我的Gradle運行與sonarqube默認sonar.test財產將有隻有test.exec,另一方面當我用sonar.test =/src/integration-test運行gradle sonarqube時,會同時存在test.exec和integrationTest.exec。

你不知道如何在一次運行中分析單元和集成測試嗎?

回答

0

我認爲你可以將它添加到您的搖籃:

sonarqube { 
    properties { 
     properties["sonar.sources"] += sourceSets.custom.allSource.srcDirs 
     properties["sonar.tests"] += sourceSets.integTest.allSource.srcDirs 
    } 
} 

只需使用+=添加更多的測試/來源。 更多信息和示例是here

編輯:

也添加報告路徑!屬性被命名爲:

sonar.surefire.reportsPath - test.testResultsDir(如果該目錄存在)

sonar.junit.reportsPath - test.testResultsDir(如果該目錄存在)

編輯:

我重寫代碼,併爲測試源在同一行,你的結構檢查

sonarqube { 
    properties { 
     property "sonar.projectName", "projectName" 
     property "sonar.projectKey", "projectKey" 
     property "sonar.host.url", "http://itsprettyprivate" 
     property "sonar.java.coveragePlugin", "jacoco" 
     // Or add it via += to properties, it is up to you ;) 
     property "sonar.sources", "src/java,src/test,src/integration-test" 
     //Tells SonarQube where the unit tests execution reports are 
     property "sonar.junit.reportsPath", "build/test-results/test" 
     //Tells SonarQube where the unit tests code coverage report is 
     property "sonar.jacoco.reportPath", "build/jacoco/test.exec" 
     //Tells SonarQube where the integration tests code coverage report is 
     property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec" 
     property "sonar.login", "admin" 
     property "sonar.password", "password" 
    } 
} 
+0

不幸的是,它不幫助,那裏我仍然只有單元測試的統計信息 –

+0

而你只是缺少報告,但測試運行?然後,你需要添加更多的屬性reportPath:'sonar.surefire.reportsPath' 'sonar.junit.reportsPath' – Hrabosch

+0

實際集成測試不運行 –