From version 132.3
edited by Vincent Massol
on 2018/11/25 11:37
To version 133.1
edited by Vincent Massol
on 2018/11/25 11:44
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -302,140 +302,4 @@
302 302  
303 303  = Test Coverage =
304 304  
305 -{{info}}
306 -We now have a [[SonarQube instance>>http://sonar.xwiki.org]] 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).
307 -{{/info}}
308 -
309 -We support both [[Jacoco>>http://www.eclemma.org/jacoco/]] and [[Clover>>http://www.atlassian.com/software/clover/overview]] to generate test coverage reports.
310 -
311 -To generate test coverage reports make sure you can [[build>>Building]] your module and then pick one of the following strategies below depending on what you wish to generate.
312 -
313 -== Single Maven Reactor ==
314 -
315 -=== Using Jacoco ===
316 -
317 -* 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}}
318 -* 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}}
319 -* Then whenever you wish to generate the full test report, run: {{code}}mvn jacoco:report -Djacoco.dataFile=/tmp/jacoco.exec{{/code}}(((
320 -{{todo}}
321 -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 https://groups.google.com/forum/#!topic/jacoco/odVzr7P5i6w
322 -{{/todo}}
323 -)))
324 -
325 -=== Using Clover ===
326 -
327 -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.
328 -
329 -1. Run the following command (adjust the local repo path):(((
330 -{{code language="none"}}
331 -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
332 -{{/code}}
333 -
334 -{{info}}
335 -* 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).
336 -* 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...).
337 -{{/info}}
338 -)))
339 -
340 -== Multiple Maven Reactors ==
341 -
342 -=== Using Jacoco ===
343 -
344 -{{todo/}}
345 -
346 -=== Using Clover ===
347 -
348 -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.
349 -
350 -1. Instrument the source code with Clover for all modules that you want to include in the report, using (adjust the paths):(((
351 -{{code language="none"}}
352 -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
353 -{{/code}}
354 -
355 -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.
356 -)))
357 -1. To generate the Clover report, execute the following from any module (adjust path):(((
358 -{{code language="none"}}
359 -mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
360 -{{/code}}
361 -)))
362 -1. Remember to clean your clover database when you're done.
363 -
364 -{{info}}
365 -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.
366 -{{/info}}
367 -
368 -Here are typical steps you'd follow to generate full TPC for XWiki:
369 -
370 -* Clean your local repo and remove any previous clover DBs:(((
371 -{{code}}
372 -rm -R ~/.m2/repository-clover/org/xwiki
373 -rm -R ~/.m2/repository-clover/com/xpn
374 -rm -R ~/.xwiki/clover
375 -{{/code}}
376 -)))
377 -* Generate coverage data for XWiki Commons:(((
378 -{{code}}
379 -cd xwiki-commons
380 -mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
381 -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
382 -{{/code}}
383 -)))
384 -* Generate Clover report just for Commons:(((
385 -{{code}}
386 -mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
387 -{{/code}}
388 -)))
389 -* Generate coverage data for XWiki Rendering:(((
390 -{{code}}
391 -cd xwiki-rendering
392 -mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
393 -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
394 -{{/code}}
395 -)))
396 -* Generate Clover report for Commons and Rendering:(((
397 -{{code}}
398 -mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
399 -{{/code}}
400 -)))
401 -* Generate coverage data for XWiki Platform:(((
402 -{{code}}
403 -cd xwiki-platform
404 -mvn clean -Pclover,integration-tests -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
405 -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
406 -{{/code}}
407 -)))
408 -* Generate full Clover report (for Commons, Rendering and Platform):(((
409 -{{code}}
410 -mvn clover:clover -N -Dmaven.clover.cloverDatabase=/Users/vmassol/.xwiki/clover/clover.db -Dmaven.repo.local=/Users/vmassol/.m2/repository-clover -nsu
411 -{{/code}}
412 -)))
413 -
414 -=== Using Clover + Jenkins ===
415 -
416 -* Install Jenkins 2.0+ and the following plugins:
417 -** Pipeline plugin
418 -** XVnc plugin
419 -* Make sure to have Maven ("mvn" executable) + VNCServer ("vncserver" executable) installed on the build agent
420 -* Build agent must be running unix
421 -* Setup a Pipeline job and make it point to the {{scm project="xwiki-jenkins-pipeline" path="scripts/clover.groovy"}}following pipeline script{{/scm}}.
422 -
423 -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.
424 -
425 -== Example Reports ==
426 -
427 -{{velocity}}
428 -#set ($url1 = $xwiki.getPlugin("zipexplorer").getFileLink($doc, "xwiki-core-clover-20080812.zip", "index.html"))
429 -#set ($url2 = $xwiki.getPlugin("zipexplorer").getFileLink($doc, "xwiki-rendering-clover-20090504.zip", "index.html"))
430 -#set ($url3 = $xwiki.getPlugin("zipexplorer").getFileLink($doc, "xwiki-rendering-clover-20101012.zip", "index.html"))
431 -
432 -* [[All Reports>>http://maven.xwiki.org/site/clover/]]
433 -* [[XWiki Commons/Rendering (2nd December 2016)>>http://maven.xwiki.org/site/clover/20161202/]]
434 -* [[XWiki Commons/Rendering (21st October 2015)>>http://maven.xwiki.org/site/clover/20151021/]]
435 -* [[XWiki Commons/Rendering/Platform/Enterprise (1st of July 2012)>>http://maven.xwiki.org/site/clover/20120701/]]
436 -* [[XWiki Commons (12 March 2012)>>http://maven.xwiki.org/site/clover/20120312/xwiki-commons/]], [[XWiki Rendering (12 March 2012)>>http://maven.xwiki.org/site/clover/20120312/xwiki-rendering/]]
437 -* [[XWiki Enterprise + Platform (17 October 2010)>>http://maven.xwiki.org/site/clover/20101017/]] (includes functional test coverage)
438 -* [[XWiki Rendering (12 October 2010)>>path:$url3]]
439 -* [[XWiki Rendering (4 May 2009)>>path:$url2]]
440 -* [[XWiki Core (12 August 2008)>>path:$url1]]
441 -{{/velocity}}
305 +See the [[TestCoverage]] page.

Get Connected