Junit test for Sonarqube repair

六月ゝ 毕业季﹏ 提交于 2019-12-11 15:15:33

问题


I am writing an automatic repair system for some specific sonarqube bugs using INRIA's spoon. I want to write Junit tests for my repair system to check whether the bug has been repaired. I want to do something like this :

X = file;
Y = repair(X);
assert(! hasSonarqubeBug(Y));

Sonarqube analysis is only available for complete projects and not individual files. Sonarlint does analyse individual files but I don't know if there is a way to write a test like this with sonarlint.


回答1:


With the Web api you're able to retrieve issues for any kind of component (files included) in Sonarqube. From the web api documentation (http(s)://sonarhost:9000//web_api/api/issues) for
GET api/issues/search parameters componentKeys:

Comma-separated list of component keys. Retrieve issues associated to a specific list of components (and all its descendants). A component can be a portfolio, project, module, directory or file.

-- Edit after comment --
To get possible new issues after changing the source code, you'll need a build and a code scan by a Sonarqube scanner. Beside Sonarlint IDE plugin, there's no local preview analysis (sonar.analysis.mode=preview for scanners is deprecated and will vanish soon).
Maybe there's some kind of hack with f.e. headless Eclipse and Sonarlint plugin (assuming you use Eclipse, don't know of headless with other IDEs) !?
You may also use the Sonarlint CLI which is not longer developed or supported, but it's still available here, though it might not work with newer Sonarqube versions.

TL;DR
It depends on your Sonarqube version, when using:
SQ 5.6.x, you may use a scanner with sonar.analysis.mode=preview, this will not publish the results to SQ Server.
SQ 6.x and later, you may try whether Sonarlint CLI still works or try with headless Eclipse. Otherwise you have to run your unitests in Eclipse and check with Sonarlint plugin.



来源:https://stackoverflow.com/questions/50697098/junit-test-for-sonarqube-repair

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!