简体   繁体   English

HTML中如何自动生成Android测试报告

[英]How to Generate Android Testing Report in HTML Automatically

I would like to automatically generate unit testing report in html format for Android application on Hudson continuous integration server.我想在 Hudson 持续集成服务器上为 Android 应用程序自动生成 html 格式的单元测试报告。

Therefore, I try to run test cases first and gather test result files in xml format.因此,我尝试先运行测试用例并收集 xml 格式的测试结果文件。 Then, I use JUnitReport Task to transform the XML result files into HTML format.然后,我使用 JUnitReport Task 将 XML 结果文件转换为 HTML 格式。

I run test cases through Android instrumentation framework.我通过 Android 仪器框架运行测试用例。 However, it only provides verbose output information rather than the standard JUnit XML format.但是,它只提供详细的 output 信息,而不是标准的 JUnit XML 格式。 I have no idea how to generate HTML unit test report without JUnit XML result files.我不知道如何在没有 JUnit XML 结果文件的情况下生成 HTML 单元测试报告。

If I run test cases using Eclipse, it can export results in XML files with time consumed information per test case.如果我使用 Eclipse 运行测试用例,它可以将结果导出到 XML 个文件中,其中包含每个测试用例的耗时信息。 Those XML files can be transformed into HTML by JUnitReport Task correctly.那些 XML 文件可以通过 JUnitReport 任务正确转换为 HTML。 As a result, it seems that it is possible to collect the test result with time consumed information.结果,似乎可以收集带有时间消耗信息的测试结果。

Is there any way to get the standard JUnit XML result file automatically after running test cases on Android instrumentation framework?在Android仪器框架上运行测试用例后,有没有办法自动获取标准JUnit XML结果文件?

We had similar problem in our company. 我们公司也有类似的问题。 We checked all the available open-source solutions and none of them was really perfect. 我们检查了所有可用的开源解决方案,但没有一个是非常完美的。 So we developed and just open-sourced a solution for it. 所以我们开发并开发了一个解决方案。 I still do not say an "ultimate" one but certainly much better than either athena or the python reporter or any after-test analysis. 我仍然没有说“终极”,但肯定比雅典娜或蟒蛇记者或任何后测试分析要好得多。 You can find it here: http://code.google.com/p/the-missing-android-xml-junit-test-runner/ 您可以在此处找到它: http//code.google.com/p/the-missing-android-xml-junit-test-runner/

It provides: 它提供:

  • separate XML file per each package involved 每个涉及的包都有单独的XML文件
  • XML files are generated on the device (need to be adb pull'ed after test) 在设备上生成XML文件(需要在测试后进行adb拉取)
  • timing of the tests is fully supported 完全支持测试的时间
  • we have full stack trace reported in failure/error case 我们在故障/错误情况下报告了完整的堆栈跟踪

Instead of analysing java source code (as in athena) or analysing the output (the python script), we extended android instrumentation runner. 我们扩展了android instrumentation runner,而不是分析java源代码(如在athena中)或分析输出(python脚本)。 So we get all the benefits of using standard command line options for test selection, coverage enabling etc. - all described here: http://developer.android.com/guide/developing/testing/testing_otheride.html#RunTestsCommand . 因此,我们可以获得使用标准命令行选项进行测试选择,覆盖启用等所有好处 - 所有这些都在此处描述: http//developer.android.com/guide/developing/testing/testing_otheride.html#RunTestsCommand

We were able to successfully run the code using standard test rules with coverage analysed by emma, all nicely reported in Jenkins. 我们能够使用标准测试规则成功运行代码,并使用emma分析覆盖范围,所有这些都在Jenkins中得到了很好的报道。

I don't think it is possible, so you need to create a utility that converts the Android test runner output into JUnit-format XML files. 我不认为这是可能的,因此您需要创建一个将Android测试运行器输出转换为JUnit格式XML文件的实用程序。

However, you won't be able to get the time-per-test value, as the Android test runner doesn't seem to output that information. 但是,您将无法获得每次测试的时间值,因为Android测试运行器似乎不会输出该信息。

I think the athena approach is the lest painfull as you can simply install the athena jar file on your system and add following ant target 我认为athena方法是最痛苦的,因为你可以简单地在你的系统上安装athena jar文件并添加以下ant目标

<property name="junit.dir" value="${basedir}/junit-results"/>
<property name="athena.jar" value="/home/cruise/athena/athena-1.1.2.jar"/>

<target name="prepare" description="Setup needed directories">
  <mkdir dir="${junit.dir}"/>
</target>

<!-- This target will compile/install tested project as well as test project to ensure tests are executed against latest code -->
<target name="athena" depends="prepare, -install-tested-project, install" description="Run tests and convert result to xml using athena">
  <exec executable="java" os="Linux" failonerror="true">
    <arg value="-cp"/>
    <arg value="${athena.jar}"/>
    <arg value="com.synaptik.athena.Athena"/>
    <arg value="${basedir}"/>
    <arg value="${junit.dir}/TEST-result.xml"/>
  </exec>
</target>

From command line it is then simply a matter of running ant athena and you have the test result in xml. 从命令行开始,只需运行ant athena就可以得到xml中的测试结果。 This will also be the target your CruiseControl script should trigger. 这也是您的C​​ruiseControl脚本应该触发的目标。

I'm in a similar situation and found https://docs.marathonlabs.io/ works great for my use case.我处于类似情况,发现https://docs.marathonlabs.io/非常适合我的用例。 Other options I've looked into:我研究过的其他选项:

  • https://docs.marathonlabs.io/ is an effort similar to spoon but seems to be more updated and better maintained. https://docs.marathonlabs.io/是一个与 spoon 类似的项目,但似乎更新和维护得更好。 It also provides nice HTML reports with additional features like tests batching, retrying and screen recording.它还提供了不错的 HTML 报告以及测试批处理、重试和屏幕录制等附加功能。
  • https://github.com/square/spoon is a test runner wrapper on top of adb shell am instrument which first runs with -e log true to get a list of available Espresso tests, and then run each test case one-by-one with -r flag so that we can be getting the XML test result from the raw text output as well runtime at the per testcase level. https://github.com/square/spoon是 adb shell am 仪器之上的测试运行器包装器,它首先使用 -e log true 运行以获取可用 Espresso 测试列表,然后逐个运行每个测试用例一个带有 -r 标志,这样我们就可以从原始文本 output 以及每个测试用例级别的运行时获得 XML 测试结果。 I didn't go down this route because it makes our overall test execution time a lot longer.我没有 go 走这条路,因为它使我们的整体测试执行时间更长。
  • Use https://github.com/jamesknowsbest/Instrumentationpretty to parse the output from instrumentation tests raw log (-r) flag.使用https://github.com/jamesknowsbest/Instrumentationpretty从仪器测试原始日志 (-r) 标志中解析 output。 We will be able to generate an XML JUnit test result with all info, except for test execution time at the test case level.我们将能够生成包含所有信息的 XML JUnit 测试结果,除了测试用例级别的测试执行时间。
  • Use adb shell am instrument -f <proto_file> to store the instrumentation result in a protobuf file, read it in and convert it to junit xml file.使用adb shell am instrument -f <proto_file>将检测结果存储在 protobuf 文件中,将其读入并转换为 junit xml 文件。 Looking at the Android instrument source code for am/instrument.java , it seems the testlevel runtime are kept when we run it with -f instead of -r.查看am/instrument.javaAndroid 仪器源代码,当我们使用 -f 而不是 -r 运行它时,似乎保留了测试级运行时。 But this means we will have to create our own protobuf parser file to generate the Junit-style XML file yourself.但这意味着我们必须创建自己的 protobuf 解析器文件来自己生成 Junit 风格的 XML 文件。
  • https://github.com/schroepf/TestLab/tree/master/android is another Open source tool created to add instrumentation data inside the application (as opposed to the client / runner side approach above). https://github.com/schroepf/TestLab/tree/master/android是另一个开源工具,用于在应用程序中添加检测数据(与上面的客户端/运行方方法相反)。 It should create a JUnit style XML result inside the Android emulator and we can then use adb pull to pull it out of the emulator afterwards.它应该在 Android 模拟器中创建一个 JUnit 样式 XML 结果,然后我们可以使用 adb pull 将其从模拟器中拉出。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM