A custom instrumentation test runner for Android that generates XML reports for integration with other tools.

Overview

Android JUnit Report Test Runner

Introduction

The Android JUnit report test runner is a custom instrumentation test runner for Android that creates XML test reports. These reports are in a similar format to those created by the Ant JUnit task's XML formatter, allowing them to be integrated with tools that support that format (e.g. continuous integration servers).

Home Page

Android JUnit report has home on the web at:

http://zutubi.com/source/projects/android-junit-report/

Note

This project is no longer required with the new, Gradle-based build system that ships with modern versions of the ADT.

License

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

Quick Start

This is a quick overview of how to integrate the runner with Ant builds. Note all modifications are made to your test project, i.e. the project which implements the JUnit tests:

  • Grab the latest jar from: http://github.com/jsankey/android-junit-report/downloads and add it to your libs/ directory.
  • Edit AndroidManifest.xml to set android:name in the instrumentation tag to: com.zutubi.android.junitreport.JUnitReportTestRunner.
  • Edit ant.properties to add the line: test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner
  • Run your tests as you would normally: $ ant debug install test
  • Pull the resulting XML report from the device (from the application under test's internal storage directory): $ adb pull /data/data/main app package/files/junit-report.xml
  • Integrate the XML with your chosen build tool.

Customising Via Arguments

The runner supports the following arguments:

  • multiFile: if set to true, a new report file is generated for each test suite. Defaults to false (a single file contains all suites).
  • 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. Defaults to junit-report.xml in single file mode, junit-report-__suite__.xml in multiple file mode.
  • reportDir: path to a directory in which to write the report file(s). May start with __external__ which will be replaced with the external storage directory for the application under test. This requires external storage to be available and WRITE_EXTERNAL_STORAGE permission in the application under test. Defaults to unspecified, in which case the internal storage directory of the application under test is used.
  • filterTraces: if true, stack traces in the report will be filtered to remove common noise (e.g. framework methods). Defaults to true.

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

See the example and/or full documentation for how to set arguments in you Ant build.

More Information

Check out the following resources for more details:

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 directory containing this README. 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:

[email protected]

All feedback is welcome.

Comments
  • Unable to instantiate instrumentation after Android Sdk Tools update (v22.0.1)

    Unable to instantiate instrumentation after Android Sdk Tools update (v22.0.1)

    Hi, I'm getting this error below since I updated my Android Sdk Tool to version 22.0.1. My instrumentation runner in the run configurations was already set to JunitReportTestRunner and it was running without problems before the update.

    06-07 16:30:12.889: E/AndroidRuntime(4966): java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{br.com.fisgo.fisgoimoveis.test/com.zutubi.android.junitreport.JUnitReportTestRunner}: java.lang.ClassNotFoundException: com.zutubi.android.junitreport.JUnitReportTestRunner in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/br.com.fisgo.fisgoimoveis.test-1.apk:/data/app/br.com.fisgo.fisgoimoveis-1.apk]

    opened by raphaeloliveira 4
  • Make writing the report more robust in case of crashes

    Make writing the report more robust in case of crashes

    First of all, sorry for force-pushing so many updates to this pull request, I made some stupid mistakes at first.

    This is more or less some proof of concept for you to review. Even with my changes we still have the problem that JUnitReportTestRunner.finish() and JUnitReportListener.close() are not called if the instrumented process crashes, leaving the XML document open with a missing </testsuites> tag.

    I did some research on how to detect whether the process crashes. Unfortunately, none of the event methods in JUnitReportTestRunner seem to get called in that case. The only option seems to be to watch the Android log for an ActivityManager output like "Crash of app <package> running instrumentation". That solution would not exactly be elegant, but I would be willing to try it out unless you come up with a better idea how to detect a crashed test application. What do you think?

    opened by sschuberth 4
  • exceptions and old report

    exceptions and old report

    It looks like when there is an exception the new report is not produced and the old one is lying around, is that possible to delete existing report when the test starts ? also is that possible to catch exceptions and still produce report ?

    opened by romk1n 2
  • the problem of the junit-report.xml

    the problem of the junit-report.xml

    when so many errors occured in the junitTests it will generate a result named junit-report.xml with error as follows: Caused by: org.dom4j.DocumentException: Error on line 493 of document file:///////junit-report.xml : XML document structures must start and end within the same entity. Nested exception: XML document structures must start and end within the same entity. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.dom4j.io.SAXReader.read(SAXReader.java:264) at hudson.tasks.junit.SuiteResult.parse(SuiteResult.java:88) at hudson.tasks.junit.TestResult.parse(TestResult.java:187) the file content is:

    without match end tag

    opened by chwoyaofei 2
  • Test runner uses APIs only available in newer Android versions

    Test runner uses APIs only available in newer Android versions

    I just downloaded the 1.4.7 JAR and ran a test on an Android 1.6 emulator, with all the default settings.

    The test runner could not start as it now uses Context.getExternalFilesDir(), which is only available from SDK level 8 (Android 2.2).

    Logcat showed the following:

    I/JUnitReportTestRunner(  252): Created with arguments: [coverage]
    I/JUnitReportTestRunner(  252): Defaulted report file to 'junit-report.xml'
    E/dalvikvm(  252): Could not find method android.content.Context.getExternalFilesDir, referenced from method com.zutubi.android.junitreport.JUnitReportListener.openOutputStream
    W/dalvikvm(  252): VFY: unable to resolve virtual method 4: Landroid/content/Context;.getExternalFilesDir (Ljava/lang/String;)Ljava/io/File;
    W/dalvikvm(  252): VFY:  rejecting opcode 0x6e at 0x0037
    W/dalvikvm(  252): VFY:  rejected Lcom/zutubi/android/junitreport/JUnitReportListener;.openOutputStream (Ljava/lang/String;)Ljava/io/FileOutputStream;
    W/dalvikvm(  252): Verifier rejected class Lcom/zutubi/android/junitreport/JUnitReportListener;
    D/AndroidRuntime(  252): Shutting down VM
    
    opened by orrc 2
  • FAILED INSTALL MISSING SHARED LIBRARY

    FAILED INSTALL MISSING SHARED LIBRARY

    Hello,

    I get failed install missing shared library errors using Android sdk tools 10. At first I though it was my setup with using android-mock and robotium but took out the test runner and everything was fine than tried your test runner again and got the same errors. Yes library was showing in apk form what I can see as far as classes.dex file space amounts.

    opened by fredgrott 2
  • Test time duration => JUnit XML file

    Test time duration => JUnit XML file

    Hi,

    I made a quick mod to android-junit-report to record test times in the XML. Up to you if you want to merge it :)

    Thanks for writing it, it's very useful!

    Tim

    opened by timsu 2
  • How to save test report file under test project directory?

    How to save test report file under test project directory?

    Now test report file is saved under data directory of target package. Is it possible to save it under test package? I simply changed mTargetContext.openFileOutput(fileName, Context.MODE_WORLD_READABLE); to mTestContext.openFileOutput(fileName, Context.MODE_WORLD_READABLE); but no files generated.

    opened by Mortimer2013 1
  • Copy the argument documentation from source code to README

    Copy the argument documentation from source code to README

    Like I've already mentioned in my previous pull request, I believe it makes more sense to really just copy & paste the text form the source code to the README so that you only have to maintain it at one place and just copy it over when it changes in the future.

    I'm aware this pull request will conflict with your recent changes to README, but you could just take my file as-is.

    opened by sschuberth 1
  • Ensure test duration is output with a decimal point

    Ensure test duration is output with a decimal point

    Currently, if running tests on an emulator/device with a locale which uses decimal commas instead of decimal points, the test duration attribute is output with a comma. This can upset JUnit XML parsers, certainly that of Jenkins.

    Now the locale is fixed to English when writing out this XML attribute. Tested before/after on an emulator with German locale.

    opened by orrc 1
  • Segmentation Fault

    Segmentation Fault

    My android test application(Robotium application) works fine without report generation. I followed the procedure you have specified for report generation. 1.First added the jar to project/libs directory. 2.Modified the AndroidManifest file , which has the following content

    3. Modified Build. xml file, which contains the following content Downloading XML test report... 4. Then issued the command ant coverage/ant run-tests 5. Compilation and everything goes fines. After the statement "Running Tests", it gives the following error " [exec] [1] Segmentation fault am instrument -w..." .

    I am not able to figure out the error. It would be very grateful if you can help me with this issue asap. :) .

    Thanking you in advance

    opened by Premika 1
Owner
Jason Sankey
Jason Sankey
Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit, Minutest, Spek, or KotlinTest.

Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit, Minutest, Spek, or KotlinTest.

Rob Fletcher 447 Dec 26, 2022
Android library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests.

Green Coffee Green Coffee is a library that allows you to run your acceptance tests written in Gherkin in your Android instrumentation tests using the

Mauricio Togneri 227 Nov 21, 2022
3 types of Tests in Android (Unit - instrumentation - UI)

UnitTestingPractice 3 types of Tests in Android Unit instrumentation (Integration) UI Unit Testing benefits confirm code work like a charm simulate Ap

Ahmed Tawfiq 8 Mar 23, 2022
kraskaska-runner: This application allows you to automatically restart specific command. Initially made for minecraft servers.

kraskaska-runner This application allows you to automatically restart specific command. Initially made for minecraft servers. Usage: Usage: kraskaska-

Kraskaska 2 Aug 30, 2022
Lbc-test-app - Test Android Senior Leboncoin

Test Android Senior Leboncoin ?? Mathieu EDET Overview Min API version : 24 This

null 0 Feb 7, 2022
Kotlin wrapper for React Test Renderer, which can be used to unit test React components in a Kotlin/JS project.

Kotlin API for React Test Renderer Kotlin wrapper for React Test Renderer, which can be used to unit test React components in a Kotlin/JS project. How

Xavier Cho 7 Jun 8, 2022
Toster - Small test dsl based on adb commands that allows you to test the mobile application close to user actions

toster Small test dsl based on adb commands that allows you to test the mobile a

Alexander Kulikovskiy 31 Sep 1, 2022
null 866 Dec 27, 2022
Linkester is an Android library that aims to help Android developers test their deep links implementation.

Linkester Linkester is an Android library that aims to help Android developers test their deep links implementation. The idea is to have a new launche

Ahmad Melegy 79 Dec 9, 2022
A powerful test framework for Android

Cafe A powerful test framework for Android named Case Automated Framework for Everyone. Home Page http://baiduqa.github.com/Cafe/ How to make Cafe dow

Baidu 367 Nov 22, 2022
A powerful test framework for Android

Cafe A powerful test framework for Android named Case Automated Framework for Everyone. Home Page http://baiduqa.github.com/Cafe/ How to make Cafe dow

Baidu 367 Nov 22, 2022
The coding challenge elbotola android test

Introduction The coding challenge(s) below will be used to assess your familiarity with the Android development environment, relevant Android related

Mohamed Elouamghari 1 Nov 2, 2021
Android background tint test project

Android Background Tint References https://developer.android.com/reference/android/view/View#attr_android:background https://developer.android.com/ref

Ashwin Dinesh 0 Nov 4, 2021
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Jan 5, 2023
TestObserver to easily test LiveData and make assertions on them.

JCenter Update LiveData Testing is currently published on JCenter - it will serve packages until February 1st, 2022. LiveData Testing packages will be

Josef Raska 395 Dec 8, 2022
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Jan 2, 2023
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing

Kotest is a flexible and comprehensive testing tool for Kotlin with multiplatform support. To learn more about Kotest, visit kotest.io or see our quic

Kotest 3.8k Jan 3, 2023
Barista makes developing UI test faster, easier and more predictable. Built on top of Espresso

Barista makes developing UI test faster, easier and more predictable. Built on top of Espresso, it provides a simple and discoverable API, removing most of the boilerplate and verbosity of common Espresso tasks. You and your Android team will write tests with no effort.

Adevinta Spain 1.6k Jan 5, 2023
Test for openbank application

openbank-test Test for openbank application Here you can find a simple test for the OpenBank application. It fetches some characters from the Marvel A

anon37894203 0 Nov 3, 2021