├── .gitignore
├── Jenkinsfile
├── README.md
├── TestResults.png
├── module1
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── DomainClass1.java
│ └── test
│ └── java
│ ├── DomainClass1IntegrationTest.java
│ └── DomainClass1Test.java
├── module2
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── DomainClass2.java
│ └── test
│ └── java
│ ├── DomainClass2IntegrationTest.java
│ └── DomainClass2Test.java
├── module3
├── pom.xml
└── src
│ ├── functionaltest
│ ├── java
│ │ └── cucumbertest
│ │ │ ├── UserSteps.java
│ │ │ └── UserTest.java
│ └── resources
│ │ └── features
│ │ └── user.feature
│ └── main
│ ├── java
│ └── users
│ │ └── User.java
│ └── resources
│ └── log4j.properties
├── pom.xml
└── testing
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Compiled class file
4 | *.class
5 |
6 | # Log file
7 | *.log
8 |
9 | .idea
10 |
11 | # BlueJ files
12 | *.ctxt
13 |
14 | target/
15 |
16 | # Mobile Tools for Java (J2ME)
17 | .mtj.tmp/
18 |
19 | # Package Files #
20 | *.jar
21 | *.war
22 | *.ear
23 | *.zip
24 | *.tar.gz
25 | *.rar
26 |
27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28 | hs_err_pid*
29 |
30 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | node {
2 | stage('Preparation') {
3 | checkout scm
4 | }
5 | stage('build and unit-test') {
6 | // all tests: other variants: only unit, integration, or all (incl. functional testing)
7 | sh 'mvn clean install -P test-all'
8 | }
9 | stage('SonarQube analysis') {
10 | withSonarQubeEnv('sonar2') {
11 | sh 'mvn sonar:sonar'
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # maven-multi-module-unittest-integrationtest-jacoco
2 |
3 | Demo of 'Maven multi module' project WITH unit- and/or integration testing with FindBugs and Jacoco code coverage
4 |
5 | # Results
6 |
7 | * Project copmlete Jacoco datafile : project-base / target / aggregate-exec / aggregate.exec
8 | * Project complete Jacoco report ; project-base / test-reporting / site / index.html
9 | * FindBugs report
10 |
11 | # Run
12 |
13 | * mvn clean install => unit testing + reporting
14 | * mvn clean install -P integration test => integration testing + reporting
15 | * mvn clean install -P test-all => unit AND integration testing + (combined) reporting !
16 |
17 | # Overview:
18 |
19 |
)
20 |
21 | # Branches: alternatives
22 |
23 | There are a few alternatives (in branches) available:
24 |
25 | * master: Behavior as shown above
26 | * multi-module-only-unit-tests: Multi module with only unit tests with the Surefire plugin in the root pom.xml
27 | * multi-module-unit-tests-try2: Multi module with only unit tests with the Surefire plugin in the pom.xml of each module
28 |
29 | In all cases, the result is available
30 |
--------------------------------------------------------------------------------
/TestResults.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johan974/maven-multi-module-unittest-integrationtest-jacoco/e4c32a5ec63bb531e32ee4ce0e17ae9163828200/TestResults.png
--------------------------------------------------------------------------------
/module1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jacoco-multi-module-demo
7 | nl.deholtmans
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | module1
13 | jar
14 | module1
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/module1/src/main/java/DomainClass1.java:
--------------------------------------------------------------------------------
1 | public class DomainClass1 {
2 | public static void main(String[] args) {
3 | DomainClass1 domainClass1 = new DomainClass1();
4 | System.out.println( "Special number is = " + domainClass1.convert( 234));
5 | }
6 | public int convert( int inputNumber) {
7 | return inputNumber * inputNumber - 2 + 4;
8 | }
9 | public int convert2( int inputNumber) {
10 | return inputNumber * inputNumber - 2 + 4;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/module1/src/test/java/DomainClass1IntegrationTest.java:
--------------------------------------------------------------------------------
1 | import org.junit.Test;
2 | import org.junit.experimental.categories.Category;
3 |
4 | import static org.junit.Assert.assertEquals;
5 |
6 | public class DomainClass1IntegrationTest {
7 | @Test
8 | // @Category( MyIntegrationTest.class) - when you use in the failsafe plugin: 'MyIntegrationTest'
9 | public void testUnitIntegrationTestTwo() {
10 | DomainClass1 domainClass1 = new DomainClass1();
11 | assertEquals( 15131, domainClass1.convert2( 123));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/module1/src/test/java/DomainClass1Test.java:
--------------------------------------------------------------------------------
1 | import org.junit.Test;
2 | import org.junit.experimental.categories.Category;
3 |
4 | import static org.junit.Assert.assertEquals;
5 |
6 | public class DomainClass1Test {
7 | @Test
8 | // @Category( MyUnitTest.class)
9 | public void testUnitTestOne() {
10 | DomainClass1 domainClass1 = new DomainClass1();
11 | assertEquals( 15131, domainClass1.convert( 123));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/module2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jacoco-multi-module-demo
7 | nl.deholtmans
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | module2
13 | jar
14 | module2
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/module2/src/main/java/DomainClass2.java:
--------------------------------------------------------------------------------
1 | public class DomainClass2 {
2 | public static void main(String[] args) {
3 | DomainClass2 domainClass2 = new DomainClass2();
4 | System.out.println( "Special number is = " + domainClass2.convert( 234));
5 | }
6 | public int convert( int inputNumber) {
7 | return inputNumber * inputNumber - 2 + 4;
8 | }
9 | public int convert2( int inputNumber) {
10 | return inputNumber * inputNumber - 2 + 4;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/module2/src/test/java/DomainClass2IntegrationTest.java:
--------------------------------------------------------------------------------
1 | import org.junit.Test;
2 | import org.junit.experimental.categories.Category;
3 |
4 | import static org.junit.Assert.assertEquals;
5 |
6 | public class DomainClass2IntegrationTest {
7 | @Test
8 | // @Category( MyIntegrationTest.class) - when you use in the failsafe plugin: 'MyIntegrationTest'
9 | public void testUnitIntegrationTestTwo() {
10 | DomainClass2 domainClass2 = new DomainClass2();
11 | assertEquals( 15131, domainClass2.convert2( 123));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/module2/src/test/java/DomainClass2Test.java:
--------------------------------------------------------------------------------
1 | import org.junit.Test;
2 | import org.junit.experimental.categories.Category;
3 |
4 | import static org.junit.Assert.assertEquals;
5 |
6 | public class DomainClass2Test {
7 | @Test
8 | // @Category( MyUnitTest.class) -- see parent.pom '
9 | public void testUnitTestOne() {
10 | DomainClass2 domainClass2 = new DomainClass2();
11 | assertEquals( 15131, domainClass2.convert( 123));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/module3/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jacoco-multi-module-demo
7 | nl.deholtmans
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | module3
13 | jar
14 | module3
15 |
16 |
17 | 1.8
18 | 1.8
19 |
20 |
21 |
22 |
23 | nl.deholtmans
24 | module1
25 | ${my.project.version}
26 |
27 |
28 | info.cukes
29 | cucumber-junit
30 | 1.2.5
31 |
32 |
33 | junit
34 | junit
35 | 4.12
36 | test
37 |
38 |
39 | info.cukes
40 | cucumber-java
41 | 1.2.5
42 | test
43 |
44 |
45 | org.slf4j
46 | slf4j-api
47 | 1.7.5
48 |
49 |
50 | org.slf4j
51 | slf4j-log4j12
52 | 1.7.25
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.codehaus.mojo
60 | build-helper-maven-plugin
61 | ${build-helper-maven-plugin.version}
62 |
63 |
64 | add-source
65 | generate-sources
66 |
67 | add-test-source
68 |
69 |
70 |
71 | src/functionaltest/java
72 |
73 |
74 |
75 |
76 | add-resource
77 | generate-sources
78 |
79 | add-test-resource
80 |
81 |
82 |
83 |
84 | src/functionaltest/resources
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/module3/src/functionaltest/java/cucumbertest/UserSteps.java:
--------------------------------------------------------------------------------
1 | package cucumbertest;
2 |
3 | import cucumber.api.java.en.Given;
4 | import cucumber.api.java.en.Then;
5 | import cucumber.api.java.en.When;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import users.User;
9 |
10 | import static org.hamcrest.CoreMatchers.is;
11 | import static org.hamcrest.MatcherAssert.assertThat;
12 | import static org.hamcrest.core.IsEqual.equalTo;
13 |
14 | public class UserSteps {
15 | Logger logger = LoggerFactory.getLogger(UserSteps.class);
16 |
17 | private User user = new User();
18 |
19 | @Given("^that the user (.*) is given a task to clear (.*) certification exam$")
20 | public void certificationName(String name, String certication) throws Throwable {
21 | logger.info( "Given: that: " + name);
22 | user.setName(name);
23 | user.setCertification(certication);
24 | }
25 |
26 | @When("^(.*) got (\\d+) marks in exam$")
27 | public void gotMarks(String name, int marks) throws Throwable {
28 | logger.info( "When: got: " + name);
29 | user.setName(name);
30 | user.setMarks(marks);
31 | }
32 |
33 | @Then("^(.*) is known as (.*) certified$")
34 | public void certifiedYes(String name, String certification) throws Throwable {
35 | logger.info( "Then: is: " + name);
36 | assertThat(name, is(user.getName()));
37 | assertThat(user.getCertification(), equalTo("Java"));
38 | assertThat(user.getResult(), is(true));
39 | }
40 | }
--------------------------------------------------------------------------------
/module3/src/functionaltest/java/cucumbertest/UserTest.java:
--------------------------------------------------------------------------------
1 | package cucumbertest;
2 |
3 | import org.junit.runner.RunWith;
4 | import cucumber.api.junit.Cucumber;
5 | import cucumber.api.CucumberOptions;
6 |
7 | @RunWith(Cucumber.class)
8 | @CucumberOptions(
9 | // features = "src/test/resources/features/user.feature",
10 | features = "src/functionaltest/resources/features",
11 | glue = "cucumbertest"
12 | )
13 | public class UserTest {
14 | }
--------------------------------------------------------------------------------
/module3/src/functionaltest/resources/features/user.feature:
--------------------------------------------------------------------------------
1 | Feature: User Certification
2 |
3 | Scenario: User is Passed
4 | Given that the user Vinod is given a task to clear Java certification exam
5 | When Vinod got 60 marks in exam
6 | Then Vinod is known as Java certified
--------------------------------------------------------------------------------
/module3/src/main/java/users/User.java:
--------------------------------------------------------------------------------
1 | package users;
2 |
3 | public class User {
4 |
5 | private String name;
6 | private String certification;
7 | private int marks;
8 |
9 | public String getName() {
10 | return name;
11 | }
12 |
13 | public void setName(String name) {
14 | this.name = name;
15 | }
16 |
17 | public String getCertification() {
18 | return certification;
19 | }
20 |
21 | public void setCertification(String certification) {
22 | this.certification = certification;
23 | }
24 |
25 | public int getMarks() {
26 | return marks;
27 | }
28 |
29 | public void setMarks(int marks) {
30 | this.marks = marks;
31 | }
32 |
33 | public boolean getResult() {
34 | if (this.marks < 60) {
35 | return false;
36 | } else {
37 | return true;
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/module3/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/johan974/maven-multi-module-unittest-integrationtest-jacoco/e4c32a5ec63bb531e32ee4ce0e17ae9163828200/module3/src/main/resources/log4j.properties
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | nl.deholtmans
8 | jacoco-multi-module-demo
9 | pom
10 |
11 | 1.0-SNAPSHOT
12 |
13 | module1
14 | module2
15 | testing
16 | module3
17 |
18 |
19 |
20 | false
21 | true
22 |
23 | 1.9.1
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 |
29 | junit
30 | junit
31 | 4.11
32 | test
33 |
34 |
35 |
36 |
37 |
38 |
39 | dev
40 |
41 | true
42 |
43 |
44 |
45 |
46 | integration-test
47 |
48 | false
49 | true
50 |
51 |
52 |
53 |
54 | test-all
55 |
56 | false
57 | false
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | nl.deholtmans
68 | jacoco-maven-plugin
69 | 1.0-SNAPSHOT
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-surefire-plugin
79 | 2.19.1
80 |
81 |
82 | ${skip.unit.tests}
83 |
84 | **/*IntegrationTest.java
85 |
86 |
87 | 1
88 |
89 |
90 |
91 |
92 |
93 | org.apache.maven.plugins
94 | maven-failsafe-plugin
95 | 2.18.1
96 |
97 |
98 | integration-tests
99 |
100 | integration-test
101 | verify
102 |
103 |
104 | ${skip.integration.tests}
105 |
106 | **/*IntegrationTest.java
107 |
108 |
109 | true
110 | ${itCoverageAgent}
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | org.codehaus.mojo
119 | findbugs-maven-plugin
120 | 3.0.4
121 |
122 |
123 |
124 |
125 | org.jacoco
126 | jacoco-maven-plugin
127 | 0.7.9
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 | prepare-unit-tests
141 |
142 | prepare-agent
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 | prepare-agent
152 |
153 | prepare-agent
154 |
155 | pre-integration-test
156 |
157 |
158 | itCoverageAgent
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/testing/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | jacoco-multi-module-demo
7 | nl.deholtmans
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 | test-reporting
12 |
13 |
14 | ${basedir}/../
15 | ${basedir}/../target/aggregate.exec
16 |
17 |
18 |
19 |
20 | nl.deholtmans
21 | module1
22 | ${my.project.version}
23 |
24 |
25 | nl.deholtmans
26 | module2
27 | ${my.project.version}
28 |
29 |
30 | nl.deholtmans
31 | module3
32 | ${my.project.version}
33 |
34 |
35 |
36 |
37 |
38 |
39 | org.apache.maven.plugins
40 | maven-surefire-plugin
41 | 2.19.1
42 |
43 |
44 |
45 |
46 | ${argLine} -Xms256m -Xmx2048m
47 | 1
48 | random
49 |
50 |
51 |
52 | org.jacoco
53 | jacoco-maven-plugin
54 |
55 |
56 | report-aggregate
57 | verify
58 |
59 | report-aggregate
60 |
61 |
62 |
63 | merge-results
64 | verify
65 |
66 | merge
67 |
68 |
69 |
70 |
71 | ${code.coverage.project.folder}
72 |
73 | **/target/jacoco.exec
74 |
75 |
76 |
77 | ${code.coverage.overall.data.folder}/aggregate.exec
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------