Andrei Manolache
Andrei Manolache

Reputation: 925

How to run my unit tests in github action workflow?

So I developed a few tests for my Android app and I need to run the tests using github actions workflow. Here is my .yml file, but I don't know how to run the tests( and get their logs):

name: Java CI with Gradle

on:
  push:
  pull_request:
    branches: Features

jobs:
  test:
    name: Run Unit Tests
    runs-on: ubuntu-18.04

    steps:
      - uses: actions/checkout@v1
      - name: set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Unit tests
        run: bash ./gradlew test --stacktrace
      - name: Unit tests results
        uses: actions/upload-artifact@v1
        with:
          name: unit-tests-results
          path: ./app

I'm not sure how to run all the app and then run all the tests, can someone give me a hint? I searched all the internet, I came across this code, but it doesn't work. My artifact is the whole app itself The tests are:
1.SignUpTest.java
2.SignInTest.java
3.AddToCart.java

Upvotes: 5

Views: 5183

Answers (1)

Chen Peleg
Chen Peleg

Reputation: 2082

After some checks apparently there is a more proper way to use Gradle in GitHub actions.

See here.

In addition it seems that you need to upgrade the Gradle permission as shown here.

So this works form me (April 2024):

name: Java CI with Gradle
on:
  push
jobs:
  test_with_gradle:
    runs-on: ubuntu-latest
    steps:
     - uses: actions/checkout@v4
     - uses: actions/setup-java@v4
       with:
         java-version: '17'
         distribution: 'temurin'

    - name: Setup Gradle
      uses: gradle/actions/setup-gradle@v3

    - name: Test
      run: |
        chmod +x gradlew
        ./gradlew test --stacktrace

Upvotes: 1

Related Questions