I have set up SonarCloud analysis for a Java project which triggers analysis when a PR is created on the git repository.
The command for triggering the check in my .travis.yml
file is:
mvn clean compile test dependency:copy-dependencies
sonar-scanner
-Dsonar.projectKey=project-key
-Dsonar.java.binaries=project/target/classes
-Dsonar.java.test.binaries=project/target/test-classes
-Dsonar.java.libraries=project/target/dependency
-Dsonar.java.test.libraries=project/target/dependency
-Dsonar.test.exclusions=project/src/test/**/*Test.java
What is expected
If someone checks-in code in a Pull Request that has a test class then it should not be considered for coverage. Only the target class should be.
What is happening
If I check-in 2 classes SonarSample.java
and SonarSampleTest.java
then SonarCloud shows coverage for both the classes.
How can I exclude the test class from being considered for coverage data?