0

I already search on Google and Stackoverflow about this Question, and don't have any answer that related to this kind of question.

So the problem is, I have a Project with Spring MVC. I create simple test like this:

@Autowired
private UserLogicService logicService;;


@Test
public void helloTrue(){
    //return should be 1
    assertThat(logicService.hello(), is(1)); //test return success
}
@Test
public void helloFalse(){
    //return should be 1
    assertThat(logicService.hello(), is(2)); //test return fail
}

And then I need to export it to XML because I read the documentation of SonarQube, HERE, The tests execution reports have to comply to the JUnit XML format.

I use SonarScanner third party to Scan my Spring Project. So I need to Export my JUnit result as XML and scan it with SonarScanner.

Is there any Setting to Automatically export JUnit Test Result to a folder as XML file?

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
David Vincent
  • 634
  • 1
  • 8
  • 33

2 Answers2

3

I would recommend using a build tool like maven or gradle. There you can find plugins which do the trick for you.

Gradle plugins

JSONStatham
  • 353
  • 4
  • 18
  • Ah forgot to mention, I use Maven. I just search and Suddenly found this http://stackoverflow.com/questions/3282767/junit3-and-junit4-xml-reports-with-maven Thank you for the answer, suddenly enlighten me. – David Vincent Nov 17 '16 at 09:31
1

Execute your tests with JaCoCo or Cobertura, then provide the paths to the coverage reports with either sonar.jacoco.reportPath or sonar.cobertura.reportPath as described in the docs.

You only need to translate to an XML format if your test engine doesn't provide a format that the language analyzer already understands.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76