{"id":13507557,"url":"https://github.com/square/spoon","last_synced_at":"2025-05-14T15:06:11.047Z","repository":{"id":6523624,"uuid":"7764585","full_name":"square/spoon","owner":"square","description":"Distributing instrumentation tests to all your Androids.","archived":false,"fork":false,"pushed_at":"2023-05-09T21:15:58.000Z","size":41911,"stargazers_count":2700,"open_issues_count":94,"forks_count":476,"subscribers_count":131,"default_branch":"master","last_synced_at":"2025-04-14T05:53:52.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://square.github.io/spoon/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-01-23T00:29:36.000Z","updated_at":"2025-04-03T11:21:53.000Z","dependencies_parsed_at":"2022-09-07T19:40:20.997Z","dependency_job_id":"5ba94299-4903-4241-90ac-7ae94bbbcb57","html_url":"https://github.com/square/spoon","commit_stats":{"total_commits":615,"total_committers":84,"mean_commits":7.321428571428571,"dds":"0.42601626016260163","last_synced_commit":"7252d7b88ba1e25469f9e9c69b00c37870ee7e15"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fspoon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fspoon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fspoon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fspoon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/spoon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169034,"owners_count":22026207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:36.110Z","updated_at":"2025-05-14T15:06:11.018Z","avatar_url":"https://github.com/square.png","language":"HTML","funding_links":[],"categories":["HTML","CN","Integration Test","Test"],"sub_categories":["[Square](https://github.com/square)","Library"],"readme":"Spoon\n=====\n\nDistributing instrumentation tests to all your Androids.\n\n\n\nIntroduction\n------------\n\nAndroid's ever-expanding ecosystem of devices creates a unique challenge to\ntesting applications. Spoon aims to simplify this task by distributing\ninstrumentation test execution and displaying the results in a meaningful way.\n\nInstead of attempting to be a new form of testing, Spoon makes existing\ninstrumentation tests more useful. Using the application APK and instrumentation\nAPK, Spoon runs the tests on multiple devices simultaneously. Once all tests\nhave completed a static HTML summary is generated with detailed information\nabout each device and test.\n\n![High-level output](website/static/example_main.png)\n\nSpoon will run on all targets which are visible to `adb devices`. Plug in\nmultiple different phones and tablets, start different configurations of\nemulators, or use some combination of both!\n\nThe greater diversity of the targets in use, the more useful the output will be\nin visualizing your applications.\n\n\n\nScreenshots\n-----------\n\nIn addition to simply running instrumentation tests, Spoon has the ability to\nsnap screenshots at key points during your tests which are then included in the\noutput. This allows for visual inspection of test executions across different\ndevices.\n\nTaking screenshots requires that you include the `spoon-client` JAR in your\ninstrumentation app. For Spoon to save screenshots your app must have the\n`WRITE_EXTERNAL_STORAGE` permission. In your tests call the `screenshot`\nmethod with a human-readable tag.\n\n```java\nSpoon.screenshot(activity, \"initial_state\");\n/* Normal test code... */\nSpoon.screenshot(activity, \"after_login\");\n```\n\nThe tag specified will be used to identify and compare screenshots taken across\nmultiple test runs.\n\n![Results with screenshots](website/static/example_screenshots.png)\n\nYou can also view each test's screenshots as an animated GIF to gauge the actual\nsequence of interaction.\n\n\n\nFiles\n-----\nIf you have files that will help you in debugging or auditing a test run, for example a log file or a SQLite database\nyou can save these files easily and have them attached to your test report.\nThis will let you easily drill down any issues that occurred in your test run.\n\nAttaching files to your report requires that you include the `spoon-client` jar and that you have `WRITE_EXTERNAL_STORAGE`\npermission.\n\n```java\n// by absolute path string\nSpoon.save(context, \"/data/data/com.yourapp/your.file\");\n// or with File\nSpoon.save(context, new File(context.getCacheDir(), \"my-database.db\"));\n```\n\n![Device Results with files](website/static/example_files.png)\n\nYou download the files by clicking on the filename in the device report.\n\nDownload\n--------\n\nDownload the [latest runner JAR][1] or the [latest client JAR][2], or just add to your dependencies:\n\nMaven:\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.squareup.spoon\u003c/groupId\u003e\n  \u003cartifactId\u003espoon-client\u003c/artifactId\u003e\n  \u003cversion\u003e1.3.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nSnapshots of the development version are available in [Sonatype's `snapshots` repository][snap].\n\n**Gradle**:\n\nThere are two Gradle plugins maintained by the community which provide integration with the Android Gradle plugin (AGP):\n\n * https://github.com/stanfy/spoon-gradle-plugin (for AGP 2.x)\n * https://github.com/jaredsburrows/gradle-spoon-plugin (for AGP 3.x)\n\n\nExecution\n---------\n\nSpoon was designed to be run both as a standalone tool or directly as part of\nyour build system.\n\nYou can run Spoon as a standalone tool with your application and instrumentation\nAPKs.\n\n```\njava -jar spoon-runner-1.3.1-jar-with-dependencies.jar \\\n    --apk ExampleApp-debug.apk \\\n    --test-apk ExampleApp-debug-androidTest-unaligned.apk\n```\n\nBy default the output will be placed in a spoon-output/ folder of the current\ndirectory. You can control additional parameters of the execution using other\nflags.\n\n```\nOptions:\n    --apk               Application APK\n    --output            Output path\n    --sdk               Path to Android SDK\n    --test-apk          Test application APK\n    --title             Execution title\n    --class-name        Test class name to run (fully-qualified)\n    --method-name       Test method name to run (must also use --class-name)\n    --no-animations     Disable animated gif generation\n    --size              Only run test methods annotated by testSize (small, medium, large)\n    --adb-timeout       Set maximum execution time per test in seconds (10min default)\n    --fail-on-failure   Non-zero exit code on failure\n    --coverage          Code coverage flag. For Spoon to calculate coverage file your app must have the `WRITE_EXTERNAL_STORAGE` permission.\n                        (This option pulls the coverage file from all devices and merge them into a single file `merged-coverage.ec`.)\n    --fail-if-no-device-connected Fail if no device is connected\n    --sequential        Execute the tests device by device\n    --init-script       Path to a script that you want to run before each device\n    --grant-all         Grant all runtime permissions during installation on Marshmallow and above devices\n    --e                 Arguments to pass to the Instrumentation Runner. This can be used\n                        multiple times for multiple entries. Usage: --e \u003cNAME\u003e=\u003cVALUE\u003e.\n                        The supported arguments varies depending on which test runner \n                        you are using, e.g. see the API docs for AndroidJUnitRunner.\n```\n\nIf you are using Maven for compilation, a plugin is provided for easy execution.\nDeclare the plugin in the `pom.xml` for the instrumentation test module.\n\n```xml\n\u003cplugin\u003e\n  \u003cgroupId\u003ecom.squareup.spoon\u003c/groupId\u003e\n  \u003cartifactId\u003espoon-maven-plugin\u003c/artifactId\u003e\n  \u003cversion\u003e1.3.1\u003c/version\u003e\n\u003c/plugin\u003e\n```\n\nThe plugin will look for an `apk` dependency for the corresponding application.\nTypically this is specified in parallel with the `jar` dependency on the\napplication.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.example\u003c/groupId\u003e\n  \u003cartifactId\u003eexample-app\u003c/artifactId\u003e\n  \u003cversion\u003e${project.version}\u003c/version\u003e\n  \u003ctype\u003ejar\u003c/type\u003e\n  \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.example\u003c/groupId\u003e\n  \u003cartifactId\u003eexample-app\u003c/artifactId\u003e\n  \u003cversion\u003e${project.version}\u003c/version\u003e\n  \u003ctype\u003eapk\u003c/type\u003e\n  \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nYou can invoke the plugin by running `mvn spoon:run`. The execution result will\nbe placed in the `target/spoon-output/` folder.  If you want to specify a test\nclass to run, add `-Dspoon.test.class=fully.qualified.ClassName`.  If you only\nwant to run a single test in that class, add `-Dspoon.test.method=testAllTheThings`.\n\nFor a working example see the sample application and instrumentation tests in\nthe `spoon-sample/` folder.\n\nTest Sharding\n-------------\n\nThe Android Instrumentation runner supports test sharding using the `numShards` and `shardIndex` arguments ([documentation](https://developer.android.com/tools/testing-support-library/index.html#ajur-sharding)).  \n\nIf you are specifying serials for multiple devices, you may use spoon's built in auto-sharding by specifying --shard:\n\n```\njava -jar spoon-runner-1.3.1-jar-with-dependencies.jar \\\n    --apk ExampleApp-debug.apk \\\n    --test-apk ExampleApp-debug-androidTest-unaligned.apk \\\n    -serial emulator-1 \\\n    -serial emulator-2 \\\n    --shard\n```\n\nThis 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`.\n\nIf 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.\n\n```\njava -jar spoon-runner-1.3.1-jar-with-dependencies.jar \\\n    --apk ExampleApp-debug.apk \\\n    --test-apk ExampleApp-debug-androidTest-unaligned.apk \\\n    --e numShards=4 \\\n    --e shardIndex=0\n```\nHowever, it will be up to you to merge the output from the shards.\n\n\nIf you use Jenkins, a good way to set up sharding is inside a \"Multi-configuration project\".\n\n - Add a \"User-defined Axis\".  Choose a name for the shard index variable, and define the index values you want (starting at zero).\n\n   ![User-defined Axis](website/static/jenkins_matrix_user_axis.png)\n\n - 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`.\n\n   ![Execute shell](website/static/jenkins_matrix_execute_shell.png)\n\n\nRunning Specific Tests\n----------------------\n\nThere 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.\n\n```\n    --e package=com.mypackage.unit_tests\n```\nSee the documentation for your instrumentation runner to find the full list of supported options (e.g. [AndroidJUnitRunner](http://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html)).\n\n\nLicense\n--------\n\n    Copyright 2013 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n\n\n [1]: https://search.maven.org/remote_content?g=com.squareup.spoon\u0026a=spoon-runner\u0026v=LATEST\u0026c=jar-with-dependencies\n [2]: https://search.maven.org/remote_content?g=com.squareup.spoon\u0026a=spoon-client\u0026v=LATEST\n [snap]: https://oss.sonatype.org/content/repositories/snapshots/\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fspoon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fspoon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fspoon/lists"}