Search code examples
pythondjangojenkinscode-coveragesonarqube

How to get tests coverage using Django, Jenkins and Sonar?


I'm trying to get test unit coverage with Sonar. To do so, I have followed these steps :

  1. Generating report with python manage.py jenkins --coverage-html-report=report_coverage
  2. Setting properties in /sonar/sonar-3.5.1/conf/sonar.properties:

sonar.dynamicAnalysis=reuseReports sonar.cobertura.reportPath=/var/lib/jenkins/workspace/origami/DEV/SRC/origami/reports/coverage.xml

When I launch the tests, the reports are generated in the right place. However, no unit tests are detected by Sonar. Am I missing a step or is everything just wrong?


Solution

  • I think the problem is that there seem to be no link between Sonar and Jenkins. It would be easier to make it with plugins.

    After installing plugins you'd just have to add a build step in the jenkins administration.

    In order to see the coverage report in Sonar you should use the "Jenkins Sonar Plugin". However it will force you to create a maven project (and a pom.xml) and as you're using Django (which already does what maven does), it may not be what you want.

    I think what you want is seeing the code coverage somewhere and maybe you should integrate it in Jenkins instead of Sonar. To do so you can use two plugins, "Jenkins Cobertura Plugin" and the "HTML Publisher plugin".

    Jenkins Cobertura Plugin will allow you to see graphically the code coverage from your coverage.xml. You can see the percentage covered in package, file, classe, line, and conditionnal. You'll just have to add the link to your coverage.xml into Jenkins in your project administration. More detail here.

    HTML Publisher plugin] will probably be useful to see the detailled code coverage by publishing the coverage report in html.