Commit 44bfd9e5 authored by Adriano Oliveira's avatar Adriano Oliveira

Create sample project with Maven and JaCoCo setup

parents
# sample-coverage-project
Sample of a multi-module Java project with test coverage report using Maven and JaCoCo.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sample-coverage-project</artifactId>
<groupId>com.konduto</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>coverage</artifactId>
<version>0</version>
<dependencies>
<dependency>
<groupId>com.konduto</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.konduto</groupId>
<artifactId>module2</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<title>JaCoCo</title>
<footer>Code Coverage Report for JaCoCo ${project.version}</footer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sample-coverage-project</artifactId>
<groupId>com.konduto</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module1</artifactId>
</project>
\ No newline at end of file
package com.konduto.module1;
/**
* Hello world!
*
*/
public class Module1 {
private String name;
private String surname;
public Module1(String name, String surname) {
this.name = name;
this.surname = surname;
}
public String getName() {
return name;
}
public Module1 withName(String name) {
this.name = name;
return this;
}
public String getSurname() {
return surname;
}
public Module1 withSurname(String surname) {
this.surname = surname;
return this;
}
}
package com.konduto;
import com.konduto.module1.Module1;
import org.junit.Assert;
import org.junit.Test;
public class TestModule1 {
@Test
public void testGetters() {
Module1 module1 = new Module1("John", "Doe");
Assert.assertEquals("John", module1.getName());
Assert.assertEquals("Doe", module1.getSurname());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sample-coverage-project</artifactId>
<groupId>com.konduto</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
</project>
\ No newline at end of file
package com.konduto.module2;
public class Module2 {
private int length;
private int height;
private int weight;
public Module2(int length, int height, int weight) {
this.length = length;
this.height = height;
this.weight = weight;
}
public int getLength() {
return length;
}
public Module2 withLength(int length) {
this.length = length;
return this;
}
public int getHeight() {
return height;
}
public Module2 withHeight(int height) {
this.height = height;
return this;
}
public int getWeight() {
return weight;
}
public Module2 withWeight(int weight) {
this.weight = weight;
return this;
}
}
package com.konduto.unit;
import com.konduto.module2.Module2;
import org.junit.Assert;
import org.junit.Test;
public class TestModule2 {
@Test
public void testGetters() {
Module2 module2 = new Module2(1, 2, 3);
Assert.assertEquals(2, module2.getHeight());
Assert.assertEquals(1, module2.getLength());
Assert.assertEquals(3, module2.getWeight());
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.konduto</groupId>
<artifactId>sample-coverage-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>sample-coverage-project</name>
<url>http://maven.apache.org</url>
<properties>
<jacoco.version>0.8.3</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<type>maven-plugin</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<modules>
<module>module1</module>
<module>module2</module>
<module>coverage</module>
</modules>
</project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment