While analysing test files , junit pre-defined rules are not getting applied

While analysing test files using junit pre-defined rules. Except this rule “TestCases should contain tests” , none of the junit rule is getting applied to the Junit test files. May I know the cause please?

command = ['java', 
          '-jar', 
          sonar_scanner_jar, 
          '-Dsonar.projectKey={}'.format(project_name), 
          '-Dsonar.host.url=http://localhost:9000',
          '-Dsonar.sources={}'.format(source_directory),
          '-Dsonar.tests={}'.format(test_directory),
          '-Dsonar.language=java', 
          '-Dsonar.sourceEncoding=UTF-8', 
          '-Dsonar.java.binaries={}'.format(binfile), 
          '-Dsonar.java.tests.binaries={}'.format(binfile),
          '-Dsonar.login=admin', 
          '-Dsonar.password=****', 
          '-Dsonar.inclusions={}'.format(','.join(srcfiles)),
          '-Dsonar.test.inclusions={}'.format(','.join(javafiles)),
          '-Dsonar.projectBaseDir={}'.format(source_directory),
          '-Dsonar.java.libraries={}'.format(cur_dir+"/sonaranalysis/lib"),
          '-Dsonar.java.test.libraries={}'.format(cur_dir+"/sonaranalysis/lib")
          ]

This is the command that I’m using. Pre-defined rules are working perfectly for the source files but not for the junit files. Kindly help with this.

1 Like

Same doubt for me as well. Is there any specific version of sonar-scanner and sonarqube server required to support junit pre-defined rules ? Kindly help me with this asap.

If specific version is not required then how can I use that pre-defined rules.