0

I'm working on a SonarQube plugin and would like to add some tests that integration test against running servers.

I'm launching the servers in docker containers, and would like to then execute sonar analysis against them from within JUnit tests.

This looks to be possible using org.sonarsource.scanner.api.EmbeddedScanner, but there might be a better way.

One drawback of using EmbeddedScanner would be that I would only be able to analyse static files on disk.

Is there a better approach?

henry
  • 5,923
  • 29
  • 46

1 Answers1

1

You can (should) unit test your analyzer by passing String to it. But as soon as you are talking about integration tests then indeed you have to work with physical files.

You can have a look at how we write "medium test" for the scanner part: https://github.com/SonarSource/sonarqube/tree/5.5/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest

Note that this BatchMediumTester utility class is not an API and is not guaranteed to be backward compatible in future versions. So you can't write "medium tests" and run them against different versions of SonarQube.

To run integration tests we are running SonarQube analysis "like a real user" by using SonarQube Scanner. We have a tool named Orchestrator that is able to start a given version of SonarQube server, install plugins, populate quality profiles, and then run analysis. See for example: https://github.com/SonarSource/sonar-scm-svn/blob/master/its/src/test/java/com/sonarsource/it/scm/SvnTest.java