Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sonar requires the coverage files to be provided during the project scanningscan. Those data files are generally recorded by plugins, servers, interpreters, ... when executing the tests and made accessible to the sonar scanner.

...

Sonar recognizes 2 types of testing that can be executed in a build for the coverage report, and it computes the union of the unit and integration test results.

  1. Unit tests
    It tests the classes or methods directly, generally by using specific test framework (Junit, testNG, etc ...)
    The "container framework" used behind the scene (Spring/ JBoss/ EJB or whatever) SHOULD NOT be used in the Unit test scope.
    External calls to test servers or third party components/anything MUST NOT be done here. These type of tests should be executable by anybody locally in an IDE.
    Due to that, it's sometimes required to make use of mock frameworks to replace the code that can't be triggered because it does require unreachable components
    The mocking SHOULD NEVER consume the developer's bandwidth, that means mocking the code should be straight-forward.
    Don't waste your time into a complicated implementation, for that there is a second test phase called "integration tests"

    Also DO NOT add "isTest" flag in your code to replace the mock, this is a common test anti pattern that lead the leads to useless tests.

  2. Integration tests
    It tests the code within the "container framework" and can make use of 3rd party components, like databases.
    The 3rd party components could be emulated, or even better, could be physically mounted locally, with the help of a docker engine for instance.
    The starting life-cycle of the those 3rd party components can be initiated/shut-downed by the build itself in a "Pre-integration/Post-integration" phase.

...

In this pom.xml, the sonar plugin must be defined, the command mvn sonar:sonar will then execute the scan

Code Block
languagexml
<plugin>
	<groupId>org.sonarsource.scanner.maven</groupId>
	<artifactId>sonar-maven-plugin</artifactId>
  	<version>x.x</version>
</plugin>

...