いくつかの単体テストと統合テストを含むプロジェクト (ProjectA) があります。
以下が構造です。
ProjectA - src/java (Java ソース コード)
- test/java (Junit 単体テスト)
- test/resources (Junit 単体テストに必要なリソース)
- src/java-test (統合テスト)
- conf (統合に必要な .xml ファイルを含む)ビルド/テスト/コンパイルの目的)
次のコマンドを実行します-それらはすべて機能しますが、build.gradle / GRADLE_HOME/init.d/*.gradle ファイルにある構成が取得内容にどのように影響するかについて疑問があります。
何かが欠けていて、欲しい場所に到達していないようです。
コマンド:
- gradle clean build -- 正常に動作します
- gradle clean build jacocoTestReport -- 正常に動作します。
- gradle clean build integrationTest jacocoTestReport -- 正常に動作します (同じ ProjectA の別のパテ ウィンドウで Tomcat インスタンスを起動して実行している場合)。
3 番目の箇条書きの操作が完了すると、Jenkins ジョブ ワークスペースに追加のフォルダー "build" とそのサブフォルダー (ソース/バージョン管理からチェックアウトされたものを除く) が表示されます。
つまり、下 -- JenkinsWorkspace
/ build
-クラス(sourceSets セクションの 1 つとして言及されている以下の .class ファイルを含む)
---- integrationTest
---- main
---- test
-リソース(これにはすべてのファイルが含まれる)ソース管理の "conf" フォルダーの下にあった .properties/.xml ファイル
-レポート(PMD/CheckStyle/Findbugs の .xml/.html ファイルと、ユニット テストまたは IT テストのいずれかのテスト結果が含まれますが、両方ではありません) --- - checkstyle
---- findbugs
---- pmd
---- jacoco
---- tests (注: これは複数形です。つまり、sourceSets の 1 つのエントリとして定義される「test」ではありません)
- jacoco (これには 2 つの .exec ファイルが含まれます。つまり、test.exec と integrationTest.exec は両方ともファイル サイズが異なります)
---- test.exec
---- integrationTest.exec
- jacocoHtml (このフォルダーには多くのフォルダーが含まれます (.html を含む)
---- somexxxfolders ---- ---- somexxfolder's.html
files
---- index.html
---- other etc files/ folders
- test-results (これにはいくつかの .xml ファイルが含まれていますが、単体テストまたは統合テストのいずれかのみを対象としていますが、特定の時点で両方のテスト タイプを対象としているわけではありません)。
つまり、「gradle clean build」を実行すると、単体テスト関連の .xml ファイルが表示され、「gradle clean build integrationTest」を実行すると、単体テストの .xml ファイルが上書きされ、表示される .xml ファイルは関連するだけになります。統合テストタスクによって/生成されます。
以下は一般的なgradleの1つです(GRADLE_HOME/init.d/some.common.gradleファイル)
//
//Extra file can hold global Gradle settings so that these dont have to be inserted in project
//specific build.gradle file.
//Filename: extraN.common<anyname>.gradle
allprojects {
apply plugin: 'java'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'
tasks.withType(Compile) {
options.debug = true
options.compilerArgs = ["-g"]
}
sourceSets {
main {
java {
// MOTE: If your project's build.gradle specify the sourceSet section, the following
// values will be overwritten by what project's build.gradle will set.
//
// If you project's sourceSet structure if different in each project, then in this
// global common .gradle file, you can define srcDir for main or other sections like
// test, integrationTest etc as shown below -- commented out. If that's the case,
// then uncomment the below line and comment out using // -- srcDir 'src/java' line
// for sourceSets.main.java section. This rule applies to other sections as well.
// srcDir 'no_src_dir_set_yet'
srcDir 'src/java'
}
resources {
srcDir 'conf'
}
}
test {
java {
srcDir 'test/java'
}
resources {
srcDir 'test/resources'
srcDir 'conf'
}
}
integrationTest {
java {
srcDir 'src/java-test'
}
resources {
srcDir 'conf'
}
}
}
def sonarServerUrl = "dev.sandbox.server.com"
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://$sonarServerUrl:9000"
property "sonar.jdbc.url", "jdbc:h2:tcp://$sonarServerUrl:9092/sonar"
property "sonar.jdbc.driverClassName", "org.h2.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
properties ["sonar.sources"] += sourceSets.main.allSource.srcDirs
//properties ["sonar.tests"] += sourceSets.test.java.srcDirs
properties ["sonar.tests"] += sourceSets.integrationTest.allSource.srcDirs
}
}
checkstyle {
configFile = new File(rootDir, "config/checkstyle.xml")
ignoreFailures = true
//sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest]
sourceSets = [sourceSets.main]
}
findbugs {
ignoreFailures = true
sourceSets = [sourceSets.main]
}
pmd {
ruleSets = ["basic", "braces", "design"]
ignoreFailures = true
}
jacoco {
toolVersion = "0.6.2.201302030002"
reportsDir = file("$buildDir/customJacocoReportDir")
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
}
test {
jacoco {
//destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
destinationFile = file("$buildDir/jacoco/test.exec")
//classDumpFile = file("$buildDir/jacoco/classpathdumps")
classDumpFile = file("$buildDir/build/classes/test")
}
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml{
enabled true
destination "${buildDir}/reports/jacoco/jacoco.xml"
}
csv.enabled false
html{
enabled true
destination "${buildDir}/jacocoHtml"
}
}
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
//additionalSourceDirs = files([sourceSets.main.allJava.srcDirs, xxxx, 'xxxxyyyy' ])
}
}
build.gradleファイルは次のようになります。
import com.tr.ids.gradle.CustomFileUtil
apply plugin: 'CustomSetup'
apply plugin: 'java'
apply plugin: 'customJarService'
apply plugin: 'customWarService'
sourceSets {
main {
java {
srcDir 'src/java'
}
}
test {
java {
srcDir 'test/java'
}
resources {
srcDir 'test/resources'
srcDir 'conf'
}
}
integrationTest {
java {
srcDir 'src/java-test'
}
}
}
// Read dependency lists from external files. Our custom plugin reads a dep-xxx.txt file for compile/test/war related .jar file entries
// where each entry is like: groupid:artifactid:x.x.x
// and these artifact jars are available in Artifactory
List depListCompile = customFileUtil.readIntoList( "$projectDir/dep-compile.txt" )
List depListTest = customFileUtil.readIntoList( "$projectDir/dep-testArtifacts.txt" )
List depListWar = customFileUtil.readIntoList( "$projectDir/dep-war.txt" )
// Define dependencies
dependencies {
// Compilation
compile depListCompile
// Unit Tests
testCompile depListTest
// Integration tests
// Everything from compile and testCompile targets
integrationTestCompile configurations.compile
integrationTestCompile configurations.testCompile
// Output of compiling "main" files
integrationTestCompile sourceSets.main.output
// Additional dependencies from war and others
integrationTestCompile depListTest, depListWar
// All configuration files
integrationTestRuntime files( 'conf' )
}
task deployTomcat( type: Copy, dependsOn: [ jar, compileIntegrationTestJava, warService ] ) {
from "$buildDir/customWar/${project.name}.war"
into "$projectDir/tomcat/webapps"
}
build {
dependsOn deployTomcat
}
task integrationTest( type: Test, dependsOn: cleanTest ) {
jacoco {
//destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
destinationFile = file("$buildDir/jacoco/integrationTest.exec")
//classDumpFile = file("$buildDir/jacoco/classpathdumps")
classDumpFile = file("$buildDir/classes/integrationTest")
}
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
apply plugin: 'eclipse'
eclipse.classpath {
// Define output directory so Eclipse does not accidentally clobber /bin
defaultOutputDir = file( 'out/classes' )
// Add integration test
plusConfigurations += configurations.integrationTestCompile
// Remove unnecessary files
file.whenMerged { classpath ->
classpath.entries.removeAll { entry -> ( entry.path.indexOf( '/build/classes/main' ) > 0 ) }
classpath.entries.removeAll { entry -> ( entry.path.indexOf( '/build/resources/main' ) > 0 ) }
}
}
私の質問:
1) "gradle clean build integrationTest" が正常に動作しているのに、build/reports/tests および build/test-results フォルダーのテスト結果を上書きするのはなぜですか。
2)テスト用の一般的なgradleファイルの下の.execファイルと、jacocoのintegrationTestタスク用のbuild.gradleで、.execファイルに付ける名前は関係ありません。常にtest.execとintegrationTest.execファイルを作成しますが、結果のbuild / jacocoHtmlフォルダーindex.html ファイルには、単体テストと統合テストの両方に関連するカバレッジ/ファイルは表示されません。これを証明するために、「gradle clean build integrationTest jacocoTestReport sonarRunner」を実行すると、ジョブのワークスペースが表示され、「.sonar」フォルダーと、「overall-xxx.exec」という別のファイルを含む build/reports/sonar フォルダーが含まれるようになりました" 一部のファイルですが、そのファイル サイズは Unit test.exec ファイル サイズと IT integrationTest.exec ファイル サイズの "合計" に近くありません。test.exec ファイルサイズよりも数バイト大きいですが。
3) ユニット テストと IT テストの両方を全体的にカバーするには、どのような構成を設定できますか。つまり、全体的に...exec ファイルのサイズが適切になります (sonarRunner タスクの実行後)。sonarRunner タスク中に、SonarRunner タスクの「jacocoSensor ステップ」が UT と IT の両方の .exec ファイルと、全体的な .exec ファイルも自動的に見ることがわかります (Sonar の優れた機能)。