Run specific Android Espresso tests by creating custom annotations

using Kotlin and command-line via Gradle

Evan Fang
2 min readSep 2, 2018

Recently I’m running an Android project. In order to make sure it’s quality and stability, we’ll usually write unit tests and instrumented tests for every feature we implemented. If you have some experience in testing method knowledge, you might hear about RAT(Release Acceptance Test), which runs on each release build to check if the build is stable for further testing. I’m faced with a problem that I wanted to run RAT tests ONLY on Jenkins triggered after each merge request being accepted.

I created a new Kotlin project with default login page on Github for example, you can clone it as a local project to run:
Now, here comes four test cases for testing login flow:

Use command line to cd to project path and run
./gradlew connectedAndroidTest
It should run all the tests successfully.

At this moment the QA(Quality Assurance) of your team might say that: “Hey! Evan, could we pick some tests for RAT? Because there are too many tests in our project, it takes a long time to run. I just wonder if we can make a quick test .”

--

--