https://github.com/linkedin/dex-test-parser
Find all test methods in an Android instrumentation APK
https://github.com/linkedin/dex-test-parser
android android-library dex linkedin test-framework testing
Last synced: 5 months ago
JSON representation
Find all test methods in an Android instrumentation APK
- Host: GitHub
- URL: https://github.com/linkedin/dex-test-parser
- Owner: linkedin
- License: bsd-2-clause
- Created: 2016-12-22T02:05:46.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2023-11-26T10:53:47.000Z (about 2 years ago)
- Last Synced: 2024-04-13T23:22:24.143Z (almost 2 years ago)
- Topics: android, android-library, dex, linkedin, test-framework, testing
- Language: Kotlin
- Size: 685 KB
- Stars: 104
- Watchers: 15
- Forks: 30
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Dex Test Parser
[](https://img.shields.io/github/workflow/status/linkedin/dex-test-parser/Merge%20checks)
## Motivation
dex-test-parser was inspired by the Google presentation "[Going Green: Cleaning up the Toxic Mobile Environment](https://www.youtube.com/watch?v=aHcmsK9jfGU)".
## What does it do?
Given an Android instrumentation apk, dex-test-parser will parse the apk's dex files and return the fully qualified method names of all JUnit 3 and JUnit 4 test methods.
Of course, you could also collect this list of method names from inside your test code by scanning the apk internally and using reflection. However, there are several reasons you may not want to do this:
* Scanning the app's classpath for test methods at runtime causes any static initializers in the classes to be run immediately, which can lead to tests that behave differently than production code.
* You might want to run one invocation of the `adb shell am instrument` command for each test to avoid shared state between tests and so that if one test crashes, other tests are still run.
## Download
Download the latest .jar via Maven:
```xml
com.linkedin.dextestparser
parser
2.3.4
pom
```
or Gradle:
```
compile 'com.linkedin.dextestparser:parser:2.3.4'
```
or you can manually download the jar from [Bintray](https://bintray.com/linkedin/maven/parser).
## Getting Started
dex-test-parser provides a single public method that you can call from Java to get all test method names.
```java
List customAnnotations = new ArrayList<>();
List testMethodNames = DexParser.findTestNames(apkPath, customAnnotations);
```
Variable customAnnotations is a list of custom tags that marks tests if you are using custom test runner for your tests.
You can also use the jar directly from the command line if you prefer. This will create a file called `AllTests.txt` in the specified output directory.
```
java -jar parser.jar path/to/apk path/for/output
```
If "path/for/output" is omitted, the output will be printed into stdout.
If you have custom test runner (com.company.testing.uitest.screenshot.ScreenshotTest in this example) and custom tag to annotate tests:
```
java -jar parser.jar path/to/apk path/for/output -A com.company.testing.uitest.screenshot.ScreenshotTest
```
## Snapshots
You can use snapshot builds to test the latest unreleased changes. A new snapshot is published
after every merge to the main branch by the [Deploy Snapshot Github Action workflow](.github/workflows/deploy-snapshot.yml).
Just add the Sonatype snapshot repository to your Gradle scripts:
```gradle
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
```
You can find the latest snapshot version to use in the [gradle.properties](gradle.properties) file.