Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ hs_err_pid*
target
.gradle
build

# integration test parameters
src/it/resources/integration-test.properties

# Local artifactory parameters
settings.xml
gradle.properties
81 changes: 80 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'jacoco'
//apply from: file('fortify-custom.gradle')

group = 'com.fortify'
Expand All @@ -17,7 +18,9 @@ buildscript {
}

repositories {
jcenter()
maven {
url artifactory_dependencies_url
}
}


Expand Down Expand Up @@ -95,12 +98,88 @@ if(hasProperty('target') && target == 'android') {
}
}

sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/it/java')
}
resources.srcDir file('src/it/resources')
}
}

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// https://stackoverflow.com/questions/19025138/gradle-how-to-generate-coverage-report-for-integration-test-using-jacoco
// answered 2019-08-02 by Brice

// Without it, the only data is the binary data,
// but I need the XML and HTML report after any test task
tasks.withType(Test) {
finalizedBy jacocoTestReport
}

// Configure the report to look for executionData generated during the test and integrationTest task
jacocoTestReport {
executionData(file("${project.buildDir}/jacoco/test.exec"),
file("${project.buildDir}/jacoco/integrationTest.exec"))
reports {
// for sonarqube
xml.enabled true
xml.destination(file("${project.buildDir}/reports/jacoco/all-tests/jacocoAllTestReport.xml"))
// for devs
html.enabled true
html.destination file("${project.buildDir}/reports/jacoco/all-tests/html")
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

integrationTest.mustRunAfter test
jacocoTestReport.dependsOn integrationTest

jacocoTestCoverageVerification {
violationRules {
rule {
// enabled = false
element = 'CLASS'
excludes = ['*Test', '*IT']

limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.0
}
}
}
}

jacocoTestCoverageVerification.dependsOn jacocoTestReport
check.dependsOn jacocoTestCoverageVerification

dependencies {
compile 'io.swagger:swagger-annotations:1.5.15'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
compile 'com.squareup.okhttp:mockwebserver:2.7.5'
compile 'com.google.code.gson:gson:2.8.1'
compile 'io.gsonfire:gson-fire:1.8.0'
compile 'org.threeten:threetenbp:1.3.5'
compile 'javax.annotation:javax.annotation-api:1.3.2'
testCompile 'junit:junit:4.12'
integrationTestCompile 'commons-codec:commons-codec:1.14'
integrationTestCompile 'org.apache.logging.log4j:log4j-api:2.12.1'
integrationTestRuntime 'org.apache.logging.log4j:log4j-core:2.12.1'
}

2 changes: 2 additions & 0 deletions gradle.properties.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifactory_dependencies_url=https://SERVER/artifactory/REPO
org.gradle.daemon=false
197 changes: 182 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,38 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<version>2.22.2</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
<argLine>${surefire.jacoco.args} -Xms512m -Xmx1500m</argLine>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<includes>
<include>com.fortify.ssc.restclient.api.ProjectControllerApiTest</include>
</includes>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<argLine>${failsafe.jacoco.args} -Xms512m -Xmx1500m</argLine>
</configuration>
</plugin>

<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
Expand All @@ -84,6 +100,12 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>

<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -114,8 +136,7 @@
</goals>
<configuration>
<sources>
<source>
src/main/java</source>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
Expand All @@ -127,8 +148,8 @@
</goals>
<configuration>
<sources>
<source>
src/test/java</source>
<source>src/test/java</source>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
Expand All @@ -138,6 +159,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -160,7 +184,123 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-version}</version>
<executions>
<!-- https://natritmeyer.com/howto/reporting-aggregated-unit-and-integration-test-coverage-with-jacoco/ -->
<execution>
<id>before-unit-test-execution</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</destFile>
<propertyName>surefire.jacoco.args</propertyName>
</configuration>
</execution>
<execution>
<id>after-unit-test-execution</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-output/jacoco-unit-tests.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-test-coverage-report</outputDirectory>
</configuration>
</execution>
<execution>
<id>before-integration-test-execution</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</destFile>
<propertyName>failsafe.jacoco.args</propertyName>
</configuration>
</execution>
<execution>
<id>after-integration-test-execution</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-test-coverage-report</outputDirectory>
</configuration>
</execution>
<execution>
<id>merge-unit-and-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}/jacoco-output/</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/jacoco-output/merged.exec</destFile>
</configuration>
</execution>
<execution>
<id>create-merged-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-output/merged.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report</outputDirectory>
</configuration>
</execution>
<execution>
<id>jacoco-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
<exclude>*IT</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0%</minimum>
</limit>
</limits>
</rule>
</rules>
<dataFile>${project.build.directory}/jacoco-output/merged.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<testResources>
<testResource>
<directory>src/it/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</testResource>
</testResources>
</build>

<profiles>
Expand Down Expand Up @@ -198,6 +338,11 @@
<artifactId>okhttp</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>mockwebserver</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
Expand Down Expand Up @@ -225,6 +370,26 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>
Expand All @@ -234,9 +399,11 @@
<swagger-core-version>1.5.15</swagger-core-version>
<okhttp-version>2.7.5</okhttp-version>
<gson-version>2.8.1</gson-version>
<threetenbp-version>1.3.5</threetenbp-version>
<threetenbp-version>1.3.5</threetenbp-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>
<log4j-version>2.12.1</log4j-version>
<jacoco-version>0.8.5</jacoco-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Loading