Spoon


Source link: https://github.com/square/spoon

Spoon

Distributing instrumentation tests to all your Androids.

Introduction

Android's ever-expanding ecosystem of devices creates a unique challenge to testing applications. Spoon aims to simplify this task by distributing instrumentation test execution and displaying the results in a meaningful way.

Instead of attempting to be a new form of testing, Spoon makes existing instrumentation tests more useful. Using the application APK and instrumentation APK, Spoon runs the tests on multiple devices simultaneously. Once all tests have completed a static HTML summary is generated with detailed information about each device and test.

Spoon will run on all targets which are visible to adb devices. Plug in multiple different phones and tablets, start different configurations of emulators, or use some combination of both!

The greater diversity of the targets in use, the more useful the output will be in visualizing your applications.

Screenshots

In addition to simply running instrumentation tests, Spoon has the ability to snap screenshots at key points during your tests which are then included in the output. This allows for visual inspection of test executions across different devices.

Taking screenshots requires that you include the spoon-client JAR in your instrumentation app. For Spoon to save screenshots your app must have the WRITE_EXTERNAL_STORAGE permission. In your tests call the screenshot method with a human-readable tag.

Spoon.screenshot(activity, "initial_state");
 /* Normal test code... */ Spoon.screenshot(activity, "after_login");

The tag specified will be used to identify and compare screenshots taken across multiple test runs.

You can also view each test's screenshots as an animated GIF to gauge the actual sequence of interaction.

Files

If you have files that will help you in debugging or auditing a test run, for example a log file or a SQLite database you can save these files easily and have them attached to your test report. This will let you easily drill down any issues that occurred in your test run.

Attaching files to your report requires that you include the spoon-client jar and that you have WRITE_EXTERNAL_STORAGE permission.

// by absolute path string Spoon.save(context, "/data/data/com.yourapp/your.file");
 // or with File Spoon.save(context, new File(context.getCacheDir(), "my-database.db"));

You download the files by clicking on the filename in the device report.

Download

Download the latest runner JAR or the latest client JAR, or just add to your dependencies:

Maven:

<dependency>
<groupId>com.squareup.spoon</groupId>
<artifactId>spoon-client</artifactId>
<version>1.3.1</version> </dependency>

Gradle: We recommend using the gradle plugin (currently maintained as a separate project).

Snapshots of the development version are available in Sonatype's snapshots repository.

Execution

Spoon was designed to be run both as a standalone tool or directly as part of your build system.

You can run Spoon as a standalone tool with your application and instrumentation APKs.

java -jar spoon-runner-1.3.1-jar-with-dependencies.jar \
  --apk ExampleApp-debug.apk \
  --test-apk ExampleApp-debug-androidTest-unaligned.apk 

By default the output will be placed in a spoon-output/ folder of the current directory. You can control additional parameters of the execution using other flags.

Options:
  --apk

Application APK
  --output

Output path
  --sdk

Path to Android SDK
  --test-apk

 Test application APK
  --title

 Execution title
  --class-name

  Test class name to run (fully-qualified)
  --method-name

 Test method name to run (must also use --class-name)
  --no-animations
  Disable animated gif generation
  --size

  Only run test methods annotated by testSize (small, medium, large)
  --adb-timeout

 Set maximum execution time per test in seconds (10min default)
  --fail-on-failure
Non-zero exit code on failure
  --coverage

 Code coverage flag. For Spoon to calculate coverage file your app must have the `WRITE_EXTERNAL_STORAGE` permission.

 (This option pulls the coverage file from all devices and merge them into a single file `merged-coverage.ec`.)
  --fail-if-no-device-connected Fail if no device is connected
  --sequential

  Execute the tests device by device
  --init-script

 Path to a script that you want to run before each device
  --grant-all

Grant all runtime permissions during installation on Marshmallow and above devices
  --e

  Arguments to pass to the Instrumentation Runner. This can be used

 multiple times for multiple entries. Usage: --e <NAME>=<VALUE>.

 The supported arguments varies depending on which test runner

  you are using, e.g. see the API docs for AndroidJUnitRunner. 

If you are using Maven for compilation, a plugin is provided for easy execution. Declare the plugin in the pom.xml for the instrumentation test module.

<plugin>
<groupId>com.squareup.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>1.3.1</version> </plugin>

The plugin will look for an apk dependency for the corresponding application. Typically this is specified in parallel with the jar dependency on the application.

<dependency>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>${
project.version
}
</version>
<type>jar</type>
<scope>provided</scope> </dependency> <dependency>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>${
project.version
}
</version>
<type>apk</type>
<scope>provided</scope> </dependency>

You can invoke the plugin by running mvn spoon:run. The execution result will be placed in the target/spoon-output/ folder. If you want to specify a test class to run, add -Dspoon.test.class=fully.qualified.ClassName. If you only want to run a single test in that class, add -Dspoon.test.method=testAllTheThings.

For a working example see the sample application and instrumentation tests in the spoon-sample/ folder.

Test Sharding

The Android Instrumentation runner supports test sharding using the numShards and shardIndex arguments ( documentation).

If you are specifying serials for multiple devices, you may use spoon's built in auto-sharding by specifying --shard:

java -jar spoon-runner-1.3.1-jar-with-dependencies.jar \
  --apk ExampleApp-debug.apk \
  --test-apk ExampleApp-debug-androidTest-unaligned.apk \
  -serial emulator-1 \
  -serial emulator-2 \
  --shard 

This will automatically shard across all specified serials, and merge the results. When this option is running with --coverage flag. It will merge all the coverage files generated from all devices into a single file called merged-coverage.ec.

If you'd like to use a different sharding strategy, you can use the --e option with Spoon to pass those arguments through to the instrumentation runner, e.g.

java -jar spoon-runner-1.3.1-jar-with-dependencies.jar \
  --apk ExampleApp-debug.apk \
  --test-apk ExampleApp-debug-androidTest-unaligned.apk \
  --e numShards=4 \
  --e shardIndex=0 

However, it will be up to you to merge the output from the shards.

If you use Jenkins, a good way to set up sharding is inside a "Multi-configuration project".

  • Add a "User-defined Axis". Choose a name for the shard index variable, and define the index values you want (starting at zero).

  • In your "Execute shell" step, use the same execution command as above, but inject the shard index for each slave node using the variable you defined above, e.g. --e shardIndex=${ shard_index } . Make sure you're passing in the correct total number of shards too, e.g. --e numShards=4.

Running Specific Tests

There are numerous ways to run a specific test, or set of tests. You can use the Spoon --size, --class-name or --method-name options, or you can use the --e option to pass arguments to the instrumentation runner, e.g.


 --e package=com.mypackage.unit_tests 

See the documentation for your instrumentation runner to find the full list of supported options (e.g. AndroidJUnitRunner).

License

Copyright 2013 Square, Inc.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Set of light and non-invasive extensions for Android RecyclerView widget. Does not use custom RecyclerView or LayoutManager. With this extensions you can create RecyclerView with following features:

  • Drag and drop reordering.
  • Implemented using RecyclerView.OnItemTouchListener
  • Support for custom "Drag frame" drawable

Comprehensive and FULL Java client for the Google Places API.

GifImageView is an Android ImageView that handles Animated GIF images.

Sometimes you don't have enough space in your layout to display a wide progressbar. So this library gives you a complete new possibility to display a progress. You can simply show a progressbar around an image. This progressbar can be configured in a lot of different ways, like color, outline, display of the percentage and so on.

Android-MonthCalendarWidget is a simple example of a responsive Month Calendar app widget for Android 4.1+.

FragmentTransactionExtended is a library which provide us a set of custom animations between fragments.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes