简体   繁体   English

如何在Spring Boot应用程序中将JUNIT测试结果导出为XML以用于SonarQube?

[英]How to Export JUNIT Test Result as XML in Spring Boot Application for SonarQube Purpose?

I already search on Google and Stackoverflow about this Question, and don't have any answer that related to this kind of question. 我已经在Google和Stackoverflow上搜索了有关此问题的信息,但没有与此类问题相关的任何答案。

So the problem is, I have a Project with Spring MVC. 所以问题是,我有一个带有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. 然后,我需要将其导出为XML,因为我阅读了SonarQube的文档HERE ,测试执行报告必须符合JUnit XML格式。

I use SonarScanner third party to Scan my Spring Project. 我使用SonarScanner第三方扫描我的Spring项目。 So I need to Export my JUnit result as XML and scan it with SonarScanner. 因此,我需要将JUnit结果导出为XML并使用SonarScanner对其进行扫描。

Is there any Setting to Automatically export JUnit Test Result to a folder as XML file? 是否有任何设置可以将JUnit测试结果自动导出为XML文件的文件夹?

I would recommend using a build tool like maven or gradle. 我建议使用诸如maven或gradle之类的构建工具。 There you can find plugins which do the trick for you. 在这里,您可以找到为您解决问题的插件。

Gradle plugins Gradle插件

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 . 使用JaCoCo或Cobertura执行测试,然后使用docs中所述的sonar.jacoco.reportPathsonar.cobertura.reportPath提供覆盖报告的路径。

You only need to translate to an XML format if your test engine doesn't provide a format that the language analyzer already understands. 如果您的测试引擎没有提供语言分析器已经可以理解的格式,则仅需要转换为XML格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从junit-frames.xsl访问TEST-result.xml的属性标签? - How to access the property tag of TEST-result.xml from junit-frames.xsl? 在eclipse中运行JUnit测试后,我可以以XML格式导出结果。 如何使用JUnit命令行获取该xml文件? - After running JUnit tests in eclipse, I can export the result in XML format. How can I get that xml file using JUnit command line? 如何使用JUnit测试SAX解析器的结果? - How to use JUnit to test the result of SAX parser? 如何插入 XML Prolog<!--?xml version = "1.0" encoding = "UTF-8"?--> 到 Rest XML 在 Spring 引导应用程序中的响应 - How to insert XML Prolog <?xml version = "1.0" encoding = "UTF-8"?>to Rest XML response in Spring Boot Application 如何为junit测试套件创建xml输出 - How to create xml output for a junit test suite 资源application.xml的spring boot失败 - spring boot with resource application.xml fails Spring启动和Angularjs Multipartfile和application / xml - Spring boot and Angularjs Multipartfile and application/xml JUnit 4结果到XML的转换 - JUnit 4 result to XML transformation Spring Test / JUnit问题-无法加载应用程序上下文 - Spring Test / JUnit problem - unable to load application context 如何在不杀死 /health 的情况下将我的 Spring Boot 应用程序默认为 application/xml? - How can I default my spring boot application to application/xml without killing /health?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM