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 the way 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 fundamental 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 are only able to merge our PR if all the Unit Test cases are passes.
I hope you know how to add Github Action in your repository if not, no worry
Follow the steps:
Go to your repository where do you want to add GitGub Action.
Click on Actions
2) Click on set up this Workflow
3) Now in there is blank.yml file will open with basic Action here we have to paste our own 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 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.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (