Show last authors
1 {{info}}
2 We now have a [[SonarQube instance>>]] showing Test coverage for both unit tests and integration tests. However it doesn't aggregate coverage data across top level modules (commons, rendering, platform, enterprise, etc).
3 {{/info}}
5 We support both [[Jacoco>>]] and [[Clover>>]] to generate test coverage reports.
7 To generate test coverage reports make sure you can [[build>>Community.Building]] your module and then pick one of the following strategies below depending on what you wish to generate.
9 == Single Maven Reactor ==
11 === Using Jacoco ===
13 * Go in the first top level module (e.g. ##xwiki-commons##) and run: {{code}}mvn clean jacoco:prepare-agent install -Djacoco.destFile=/tmp/jacoco.exec -Djacoco.append=false -Plegacy,integration-tests -Dxwiki.revapi.skip=true -Dmaven.test.failure.ignore=true{{/code}}
14 * Go in all the other top level modules you wish to add and run: {{code}}mvn clean jacoco:prepare-agent install -Djacoco.destFile=/tmp/jacoco.exec -Djacoco.append=true -Plegacy,integration-tests -Dxwiki.revapi.skip=true -Dmaven.test.failure.ignore=true{{/code}}
15 * Then whenever you wish to generate the full test report, run: {{code}}mvn jacoco:report -Djacoco.dataFile=/tmp/jacoco.exec{{/code}}(((
16 {{todo}}
17 Jacoco supports generating report from a single module, it even supports generating aggregated report from several modules using the report-aggregate mojo introduced in 0.7.7 (but note that I don't know if that includes coverage induced by module B on module A). However jacoco doesn't seem to support the ability to execute several maven reactors (for example for building code located in various github repositories), using the same jacoco exec file and then generate a report for that. See also!topic/jacoco/odVzr7P5i6w
18 {{/todo}}
19 )))
21 === Using Clover ===
23 Go to the top level module containing children modules for which to generate a Clover report. Note that you won't be able to aggregate Clover data across different Maven runs with this strategy so you really need a single parent module.
25 1. Run the following command (adjust the local repo path):(((
26 {{code language="none"}}
27 mvn clean clover:setup install clover:aggregate clover:clover -Pclover,integration-tests,dev,jetty,hsqldb -Dxwiki.revapi.skip=true -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -Dmaven.test.failure.ignore=true -nsu
28 {{/code}}
30 {{info}}
31 * You might need to run the "install" goal instead of the "test" one if your local Maven repository doesn't already contain some test jars (apparently and for some reason Maven won't download them from the remote repository under some conditions).
32 * Note that we use ##-Dmaven.repo.local## to use a different Maven local repository so that instrumented source code and built binaries don't find their way in your standard local repository (which you could then deploy by mistake, or that'll simply fail your tests later on when you don't run with the Clover profile since instrumented artifacts require the Clover JAR to be present in the classpath at runtime...).
33 {{/info}}
34 )))
36 == Multiple Maven Reactors ==
38 === Using Jacoco ===
40 {{todo/}}
42 === Using Clover ===
44 Use a single Clover database to which you add coverage information as you build modules one after another. This strategy is especially useful when you wish to manually run some modules and ensure that coverage data aggregate in a single place so that when you generate the report you have the result of all your runs.
46 1. Instrument the source code with Clover for all modules that you want to include in the report, using (adjust the paths):(((
47 {{code language="none"}}
48 mvn clover:setup install -Pclover,integration-tests,dev,jetty,hsqldb -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dxwiki.revapi.skip=true -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
49 {{/code}}
51 When tests are executed they'll generate coverage data in the specified Clover database. Since there's a single Clover there's no need to merge Clover databases as in strategy 1 above.
52 )))
53 1. To generate the Clover report, execute the following from any module (adjust path):(((
54 {{code language="none"}}
55 mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
56 {{/code}}
57 )))
58 1. Remember to clean your clover database when you're done.
60 {{info}}
61 If you don't wish failing tests to stop the generation of the coverage report, you should pass ##-Dmaven.test.failure.ignore=true## on the command line.
62 {{/info}}
64 Here are typical steps you'd follow to generate full TPC for XWiki:
66 * Clean your local repo and remove any previous clover DBs:(((
67 {{code}}
68 rm -R ~/.m2/repository-clover/org/xwiki
69 rm -R ~/.m2/repository-clover/com/xpn
70 rm -R ~/.xwiki/clover
71 {{/code}}
72 )))
73 * Generate coverage data for XWiki Commons:(((
74 {{code}}
75 cd xwiki-commons
76 mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
77 mvn clover:setup install -Pclover,integration-tests -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -Dmaven.test.failure.ignore=true -Dxwiki.revapi.skip=true -nsu
78 {{/code}}
79 )))
80 * Generate Clover report just for Commons:(((
81 {{code}}
82 mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
83 {{/code}}
84 )))
85 * Generate coverage data for XWiki Rendering:(((
86 {{code}}
87 cd xwiki-rendering
88 mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
89 mvn clover:setup install -Pclover,integration-tests -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -Dmaven.test.failure.ignore=true -Dxwiki.revapi.skip=true -nsu
90 {{/code}}
91 )))
92 * Generate Clover report for Commons and Rendering:(((
93 {{code}}
94 mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
95 {{/code}}
96 )))
97 * Generate coverage data for XWiki Platform:(((
98 {{code}}
99 cd xwiki-platform
100 mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
101 mvn clover:setup install -Pclover,integration-tests -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -Dmaven.test.failure.ignore=true -Dxwiki.revapi.skip=true -nsu
102 {{/code}}
103 )))
104 * Generate full Clover report (for Commons, Rendering and Platform):(((
105 {{code}}
106 mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
107 {{/code}}
108 )))
110 === Using Clover + Jenkins ===
112 * Install Jenkins 2.0+ and the following plugins:
113 ** Pipeline plugin
114 ** XVnc plugin
115 * Make sure to have Maven ("mvn" executable) + VNCServer ("vncserver" executable) installed on the build agent
116 * Build agent must be running unix
117 * Setup a Pipeline job and make it point to the {{scm project="xwiki-jenkins-pipeline" path="scripts/clover.groovy"}}following pipeline script{{/scm}}.
119 Note that the Clover pipeline script will generate a report with differences from the previous passing report showing the contributions (positive and negative) of each module to the global TPC.
121 == Example Reports ==
123 * [[All Reports>>]]
124 * [[XWiki Commons/Rendering (2nd December 2016)>>]]
125 * [[XWiki Commons/Rendering (21st October 2015)>>]]
126 * [[XWiki Commons/Rendering/Platform/Enterprise (1st of July 2012)>>]]
127 * [[XWiki Commons (12 March 2012)>>]], [[XWiki Rendering (12 March 2012)>>]]
128 * [[XWiki Enterprise + Platform (17 October 2010)>>]] (includes functional test coverage)
129 * [[XWiki Rendering (12 October 2010)>>]]
130 * [[XWiki Rendering (4 May 2009)>>]]
131 * [[XWiki Core (12 August 2008)>>]]

Get Connected