android junit report

时间 : 14-09-17 栏目 : Android, 移动开发, 集成测试 作者 : noway 评论 : 0 点击 : 992 次

Contents

Introduction

The Android JUnit report test runner is a custom instrumentation test runner for Android that creates XML test reports. It's the glue between your Android unit tests and the rest of your toolkit. By exporting your test results in a format mostly-compatible with that used by the AntJUnit task, the runner allows you to leverage any tools that support this format for your Android projects.

For the Impatient

Just want to get started? Refer to the quick start instructions on the project home page.

Motivation

I originally created the runner to integrate my own Android projects with our Pulse continuos integration server. There is nothing Pulse-specific about the runner, though. Hence I've open sourced it so other Android developers can benefit and (perhaps) contribute.

License

This code is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

How It Works

This test runner may be used as a drop-in replacement for the standardInstrumentationTestRunner provided in the Android SDK. It is in fact an extension of that runner, supporting the same functionality with the addition of XML report generation.

To be consistent with existing SDK support for generating coverage reports, this runner outputs its XML report in the file storage area for the application under test. By default, the report file is produced at:

/data/data/<application under test package>/files/junit-report.xml

The file may be retrieved from the device using adb pull (see below for more details). You may also customise the output location, file name and even choose to produce multiple output files (one per suite). Again, details may be found below.

Note: by default only the application under test has full access to the directory where the report is stored. You will not be able, for example, to list the contents of the directory unless you have a rooted device. The runner marks the file as world-readable, though, so knowing the full path you are able to pull it from the device.

Using the Runner

Obtaining the Jar

First you will need to obtain a release jar file containing the runner. You can build from source (see below), but it's probably easier to just grab the latest jar from the downloads page. You can also grab the latest release build directly from our Pulse build server (click on "jar" in the "featured artifacts" table on the right of the page.)

Using with Ant Builds

To use this runner with an Ant build (based on the Android SDK support for Ant):

  • Add android-junit-report-<version>.jar to your test project's libs/directory.
  • Edit your test project's AndroidManifest.xml to set android:name in the<instrumentation> tag to:com.zutubi.android.junitreport.JUnitReportTestRunner.
  • Edit your test project's ant.properties to add the line:
    test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner

These steps will cause your tests to be executed with the custom runner, which will produce the junit-report.xml file in the internal storage area for the project under test. To retrieve the file from the device, you can use Ant to run an adb pull, for example:

<target name="fetch-test-report">
  <xpath input="${tested.project.dir}/AndroidManifest.xml"
         expression="/manifest/@package" output="tested.package"/>

  <echo>Downloading XML test report...</echo>
  <mkdir dir="${reports.dir}"/>
  <exec executable="${adb}" failonerror="true">
  <arg line="${adb.device.arg}"/>
    <arg value="pull" />
    <arg value="/data/data/${tested.package}/files/junit-report.xml"/>
    <arg value="${reports.dir}/junit-report.xml"/>
  </exec>
</target>

The runner comes with an example project that includes custom Ant rules intests/custom_rules.xml.

Using with Eclipse

When running within Eclipse, there is not much call for XML test reports. However, assuming you have edited your test project's manifest to specify this custom runner (as described above), you may also need to tell Eclipse to use this runner to avoid problems. You can do this by:

  • Adding android-junit-report-<version>.jar to the build path of your test project in Eclipse. Note with newer versions of the ADT this should be done automatically for you.
  • Ensuring all existing run configurations for unit tests specify an Instrumentation runner of:
    test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner

If you see an error about not being able to find a target package forandroid.test.InstrumentationTestRunner, it is likely you have an existing run configuration that is set to use the default runner. You can recreate any such configurations and the issue will disappear.

Customising Via Arguments

The runner supports various arguments, summarised below, to customise its behaviour.

Supported Arguments

multiFile

If set to true, a new report file is generated for each test suite. If false, a single report is generated containing all suites.

Default: false

reportDir

If specified, absolute path to a directory in which to write the report file(s). May begin with__external__, which will be replaced with the path for the external storage area of the application under test. This requires external storage to be available andWRITE_EXTERNAL_STORAGE permission in the application under test.

Default: unspecified (reports are written to the internal storage of the application under test)

reportFile

The name of the report file to generate (single file mode) or a pattern for the name of the files to generate (multiple file mode). In the latter case the string __suite__ will be substituted with the test suite name to produce the file name for each suite. See the reportDirargument for the destination of the report files.

Defaultjunit-report.xml in single file mode, junit-report-__suite__.xml in multiple file mode.

filterTraces

If true, stack traces in the report will be filtered to remove common noise (e.g. framework methods).

Default: true

Specifying Arguments

To specify arguments, use the -e flag to adb shell am instrument, for example:

$ adb shell am instrument -w -e reportFile my-report.xml \
  com.example.test/com.zutubi.android.junitreport.JUnitReportTestRunner

If you need to pass arguments in your Ant build, you must override the built-in run-tests target. As an example, if you prefer multiple output files (which are more compatible with some tools), you need to set the multiFile argument to true. In this case you will also need to pull the whole directory of files from the device after running your tests:

<target name="custom-test">
  <xpath input="${tested.project.dir}/AndroidManifest.xml"
         expression="/manifest/@package" output="tested.package"/>

  <echo>Running tests...</echo>
  <exec executable="${adb}" failonerror="true">
    <arg line="${adb.device.arg}"/>
    <arg value="shell"/>
    <arg value="am"/>
    <arg value="instrument"/>
    <arg value="-w"/>
    <arg value="-e"/>
    <arg value="reportDir"/>
    <arg value="__external__/my-reports"/>
    <arg value="-e"/>
    <arg value="multiFile"/>
    <arg value="true"/>
    <arg value="${tested.package}/${test.runner}"/>
  </exec>
<target>

The example project includes a sample target of this type in tests/custom_rules.xml.

Report Format

As stated above, the XML report format is based on the Ant JUnit task's XML formatter. A few caveats apply:

  • In the default single file mode, multiple suites are all placed in a single file under a root <testsuites> element. In multiple file mode each XML file contains a single suite.
  • Redundant information about the number of nested cases within a suite is omitted.
  • Durations are present on cases, but omitted from suites. Adding them to suites would require buffering that the runner specifically avoids due to memory usage concerns.
  • Neither standard output nor system properties are included.

The differences mainly revolve around making this reporting as lightweight as possible. The report is streamed as the tests run, making it impossible to, e.g. include the case count in a<testsuite> element. If required this information can be added to the reports by post-processing.

The format is intended to be "compatible enough" for integration with existing tools. In my particular case I use the reports with our own Pulse continuous integration server, so compatibility with it was my first target. If you find an incompatibility with another tool, let me know (see below) and I will see what can be done.

Building From Source

If you would like to modify the runner, or build it yourself for any other reason, you will need:

  • A JDK, version 1.5 or later.
  • The Android SDK (or at least a stub android.jar as provided in the SDK).
  • Apache Ant version 1.7 or later.

To run a build:

  • Create a file local.properties in the top-level directory. In this file, define the location of an android.jar to build against, for example:
    android.jar=/opt/android/platforms/android-14/android.jar

    where /opt/android is the root of an Android SDK.

  • Run ant in this same directory:
    $ ant

    The jar will be created at build/android-junit-report-dev.jar.

Feedback

If you have any thoughts, questions etc about the runner, you can contact me at:

jason@zutubi.com

Or you can submit an issue or pull request via GitHub. All feedback is welcome.

除非注明,文章均为( noway )原创,转载请保留链接: http://blog-old.z3a105.com/?p=139

android junit report:等您坐沙发呢!

发表评论





       ==QQ:122320466==

 微信    QQ群


0

Aujourd’hui, une partie avec le développement du e-commerce, achats en ligne est devenu une partie de la vie pour beaucoup de gens. La mariage a commencé achats en ligne. Si vous choisissez achats les mariages en ligne, il peut être beaucoup moins cher que le salon de la Robe de mariée pas chermariée local, réduisant le budget de mariage. vous pouvez avoir beaucoup de choix si acheter de mariage en ligne. vous pouvez ramasser une robe de mariée bon marché sur Internet.
Piercing fascinerande figur, och nu tittar vi på 2016 senast brudklänning, kan du vara den vackraste bruden det!2016 senaste Bra brudklänning, söt temperament Bra design, romantiska spetsar blomma kjol, som du lägger till en elegant och charmig temperament.Kvinnan tillbaka mjuka linjer, människor brudklänningofta få en känsla av oändlig frestelse. Fall 2016 mässan, lämnar uppgifter om ditt bröllop charmig.
Yesterday afternoon, the Chinese team was training in the Guangzhou Gymnasium, when the reporter asked Zhao Yunlei the feeling of wearing the new cheap jersey , cheap jerseys online shopshe readily took a shirt from the bag crumpled ball to reporters, and she said with a smile: ” This shirt is light. ”Zhao Yunlei said: “Our material is very light like with the clothes of the tennis King Nadal, Federer, after the sweat, sweat does not drip down to the ground, when we do move, it is easy pace slipping if the sweat drip on the floor.”Tennis players Zhang Yawen, told reporters: “You might think the clothes attached to the body, fearing we swing will be affected, in fact, we do not feel anything, because the clothes are very light, very soft, put on quite comfortable. And it’s particularly good clothes to dry, washing and will dry in 15 minutes. ”
China’s sports enthusiasts NFL sweatshirt with mad love and the pursuit of, and therefore, NFL jerseys have a good market in China and development. China is a populous country, is the consumer, the economic momentum is so good, the sales prospects sportswear is immeasurable. With hot sales sweatshirt, but also to promote the importance of sports fans, on health, on the other hand is a matter of concern for the World Cup, fans wearing NFL jerseys and also can express themselves more fully love and obsession Therefore, NFL jerseys Wholesale jerseys online shopwholesale has good prospects and development in China.
ANTA-ANTA Sports Products Limited, referred to as ANTA Sports, Anta, is China’s leading sporting goods companies, mainly engaged in the design, development, manufacture and marketing of ANTA brand sporting goods, including sports footwear, apparel and accessories. Anta sweatshirt design advantages, warm stretch knit fabric, using Slim version of model, more personal fit, bid farewell to bloated, so wearing more stylish.GUIRENNIAO-This logo is a spiritual totem, smooth graphics implication unstoppable force; flexible deliver an elegant arc Wholesale jerseys china shop movement, strength and speed of the United States, a symbol of passion and rationality publicity “Heart” and “meaning”, “concept” unity; pass the fearless and enterprising mind, showing beyond the realm of self, to unstoppable force to create the future.XTEP-Xtep (China) Co., Ltd. is a comprehensive development wholesale jerseys china shop, production and marketing of Xtep brand (XTEP) sports shoes, clothing, bags, caps, balls, socks mainly large sporting goods industry enterprises.
There are a lot of fans in identifying the authenticity of the above cheap jerseys have great distress, so here to i will show you some methods to definitely affordable inexpensive cheap jerseys : Firstly, we should look at if it is working fine. China has been called the world’s factory, a lot cheap jerseys factories in China have foundries, but our cheap jerseys are all from here! Secondly, should to see whether it is the , we all know that it is difficult to get out of print once a genuine cheap cheap jerseys free shipping jersey was print. and we have all kind of stocka on the whole website, in other words, we have all you want ! Finally, look at the price, our price is not necessarily the lowest in the whole website but it must be most fair on the whole website, we certainly you will not regret later when you buy it. Of course, except that cheap jerseys, we also have the other products, such as socks, leggings and some other related products, everyone can enjoy the best services of here!

KUBET