GitHub Action for Unit Testing in Android

Dev D
4 min readSep 6, 2020

Jasper.Ai

GitHub Actions made Unit Testing Report easy, let's find out how

Photo by Rubaitul Azad on Unsplash

GitHub Actions are very popular for automating workflows; if you want to be one step ahead, use beautiful GitHub Actions in your repositories.

GitHub Actions make it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work as you want.

Here we will discuss How to integrate GitHub Action for Unit Testing and the benefits of using this action.

Unit tests are the actual tests in your app testing strategy. By creating and running unit tests against your code, you can easily verify that the logic of individual units is correct. Running unit tests after every build help you to quickly catch and fix software regressions introduced by code changes to your app.

What if we can only merge our PR if all the Unit Test cases are passed?

In this situation, Github Action can help.

We will add one awesome Github Action in our Repository and see the magic.

I hope you know how to add GitHub Action to your repository if not, no worry

Follow the steps:
Go to your repository where you want to add GitHub Action.

  1. Click on Actions

2) Click on set up this Workflow

3) Now in there is a blank.yml file that will open with primary Action here; we have to paste our Action

Paste this one:

name: Android CI
on:
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

# Execute unit tests
- name: Unit Test
run: ./gradlew testDebugUnitTest

- name: Android Test Report
uses: asadmansr/android-test-report-action@v1.2.0
if: ${{ always() }} # IMPORTANT: run Android Test Report regardless

Now please create the PR and see the magic; highlighted one is our GitHub Action for the Unit test; it will not let you merge the PR until all the test cases will get a pass:

If you want to see the Test Report, we can check to go to Action Page like before

There we have our GitHub Actions and related jobs listed there; in our case, we have a job name test, and on the right-hand side, we have our jobs.

Now click on the Android Test Report.

You can see the details Test Case report there.

That's it; if you like this article, please Clap, and don't forget to follow the latest blogs.

Thanks for reading, follow me for more blogs and tips.
Amazon Fashion

Each clap count

--

--

Engineering Manager with 18 years of Mobile and Web Application Development experience.Short bio https://linktr.ee/learnfromme