Android automated testing with Jenkins and Firebase


Imagine 10 developers are working on same project. They push code on repository then manager generate the build and test it. While testing, manager found bugs in the build and he/she failed the build. After that developer fixed the bug and repeat the same process.

If we make this process automated, then we just need to develop feature and fix the bug if we find it after pushing code. We can achieve this by Jenkins and gcloud CLI. So let’s start how we can implement it.


First you need to install Jenkins. Download Jenkins from here.

Now add Github plug in,Gradle Plug in & Android Emulator Plug in from Manage Jenkins > Manage Plugins.

Once the plugin added, create job in Jenkins and choose Freestyle project. We will Configure project letter.

Now download and setup gcloud. Please follow steps from this link.


Now come to Jenkins home page and click on Credential.

Add your credential as below

Scope: Global(Jenkins, nodes, items, all child item, etc)

Username: your github username

Password: your github password

Click on save


Now we will configure job. Click Job and then from left menu click on Configure

In General section click on GitHub project and add project url(in my case it’s gitlab project url)

Now come to the Source code Management section and select Git

Add your Repository url and select your Credentials that you added.

You can also change Branches to build/

Select Build Triggers as per your requirements.


Now we will set Build in job Configure.

Click on Add build step and select Invoke Gradle script

Select Use Gradle Wrapper option

Add tasks like build — stacktrace. If you want to ignore lint add -x lint

build — stacktrace -x lint

build :app:assembleDebugAndroidTest (To create instrumentation test apk)

Now add Execute shell and write below Commands

For login gcloud

gcloud auth activate-service-account — key-file=/home/sanjay/todo-app-1ea25815be22.json

To create .json file check this

After that set your project

gcloud config set project todo-app-d2434(Project ID)

To run instrumentation test on Firebase

gcloud firebase test android run — type instrumentation — app app-debug.apk — test app-debug-androidTest.apk — device model=Nexus6,version=21,locale=en,orientation=portrait — device model=Nexus7,version=19,locale=fr,orientation=portrait


Set the artifacts

Now go to the Post-build Actions

Add Archive the artifacts

In Files to archive add **/*.apk

Apply all changes and Build Now to test the implementations. This will fetch your code from git and create a build. Then upload both apk on the Firebase for the instrumentation testing.

If you liked this post, kindly give me some claps and follow me for more posts like this one. Be sure to leave a comment if you have any thoughts or questions.