Reputation: 4106
I'm trying to get test unit coverage with Sonar. To do so, I have followed these steps :
python manage.py jenkins --coverage-html-report=report_coverage
/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?
Upvotes: 4
Views: 7410
Reputation: 1158
On Jenkins I found that coverage.xml has paths that are relative to the directory in which manage.py jenkins is run.
In my case I need to run unit tests on a different machine than Jenkins. To allow Sonar to use the generated coverage.xml, it was necessary for me to run the tests from a folder in the same spot relative to the project as the workspace directory on Jenkins.
Say I have the following on Jenkins /local/jenkins/tmp/workspace/my_build + my_project + app1 + app2 Say on test machine I have the following /local/test + my_project + app1 + app2
I run unit tests from /local/test on the test machine. Then coverage.xml has the correct relative paths, which look like my_project/app1/source1.py or my_project/app2/source2.py
Upvotes: 0
Reputation: 4282
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.
Upvotes: 2