Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle CI doesn't launch unit tests #11513

Closed
fabienpuissant opened this issue Dec 5, 2024 · 5 comments · Fixed by #11547
Closed

Gradle CI doesn't launch unit tests #11513

fabienpuissant opened this issue Dec 5, 2024 · 5 comments · Fixed by #11547
Assignees
Labels
area: bug 🐛 Something isn't working theme: gradle

Comments

@fabienpuissant
Copy link
Collaborator

fabienpuissant commented Dec 5, 2024

It seems that the gradle ci don't launch unit test only IT.

I have tried to put a failing unit test and the ci was green

Is this the behaviour or a misconfiguration on my side ?

A possible working solution

github-actions.yml

jobs:
  tests:
    name: tests
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: 'Setup: checkout project'
        uses: actions/checkout@v4
      - name: 'Setup: environment'
        id: setup
        uses: ./.github/actions/setup
      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2
      - name: 'Test: run unit tests'
        run: ./gradlew clean test --no-daemon
      - name: 'Test: run integration tests'
        run: ./gradlew clean integrationTest --no-daemon
@fabienpuissant fabienpuissant changed the title Gradle CI don't launch unit tests Gradle CI doesn't launch unit tests Dec 5, 2024
@pascalgrimaud pascalgrimaud added area: bug 🐛 Something isn't working theme: gradle and removed area: triage labels Dec 5, 2024
@renanfranca renanfranca self-assigned this Dec 6, 2024
@renanfranca
Copy link
Contributor

@fabienpuissant : I looked at a random build action: feat(liquibase): async liquibase configuration should not be activated if liquibase is disabled. At least for this example, the tests were executed:

> Task :test

JwtReaderTest > should not authenticate user from empty token STANDARD_OUT
    2024-12-05T23:23:09.354Z  INFO   --- [    Test worker] t.j.f.s.a.i.primary.JwtReader            : Invalid empty JWT token

JwtReaderTest > should not authenticate user from blank token STANDARD_OUT
    2024-12-05T23:23:09.359Z  INFO   --- [    Test worker] t.j.f.s.a.i.primary.JwtReader            : Invalid empty JWT token

JwtReaderTest > should not authenticate user from invalid token STANDARD_OUT
    2024-12-05T23:23:09.481Z  INFO   --- [    Test worker] t.j.f.s.a.i.primary.JwtReader            : Invalid JWT token
    2024-12-05T23:23:09.482Z TRACE   --- [    Test worker] t.j.f.s.a.i.primary.JwtReader            : Invalid JWT token: Invalid compact JWT string: Compact JWSs must contain exactly 2 period characters, and compact JWEs must contain exactly 4.  Found: 0

Here is the part of the github-actions.yml responsible for that:

      - name: 'Test: verify ${{ matrix.app }}'
        if: steps.tests-requirement-check.outputs.execute_tests == 'true'
        working-directory: /tmp/jhlite/${{ matrix.app }}/
        run: |
          if [ -f 'mvnw' ]; then
            ./mvnw clean verify -Dsonar.qualitygate.wait=true sonar:sonar
          elif [ -f 'gradlew' ]; then
            ./gradlew clean build sonar --no-daemon --info
          else
            npm install
            npm test
          fi

Please, could you provide an example that reproduces the not desired behavior?

@fabienpuissant
Copy link
Collaborator Author

@renanfranca It's on a generated app

See https://github.com/fabienpuissant/test-jh-lite-gradle-ci/actions/runs/12202622941

should fail because of : https://github.com/fabienpuissant/test-jh-lite-gradle-ci/blob/main/src/test/java/com/mycompany/myapp/FailingTest.java

In the test-ci for jhlite it seems to be ok 😄

@renanfranca
Copy link
Contributor

renanfranca commented Dec 6, 2024

@fabienpuissant : Ohh, thanks! I see now. Today, if you add the Jacoco module, it will work fine without the need to change the github-actions.yml, because Jacoco links both unit and integration tests.

To work out of the box without Jacoco, it is going need to change the Gradle module to directly link unit and integration tests. Then, when adding Jacoco, remove that link to make Jacoco the glue.

@pascalgrimaud and @murdos : can you share your opinion here, please? About which is the best approach.

@atomfrede
Copy link
Member

atomfrede commented Dec 6, 2024

Not 100% sure just on my mobile, but with the soft ordering should run after for the integration test phase this does not define a dependency. So when just executing integrationtest this does not imply running unit tests.

In the ci config running unit and integration tests in dedicated phases should be fine. I would not do the clean before such that integration tests can use e.g.the compiled classes which have been created already before.

@renanfranca
Copy link
Contributor

renanfranca commented Dec 6, 2024

To work out of the box without Jacoco, it is going need to change the Gradle module to directly link unit and integration tests. Then, when adding Jacoco, remove that link to make Jacoco the glue.

@fabienpuissant : I think your solution is better and more flexible 😉. Even if we add the Jacoco module, the CI configuration will need to be updated to execute Jacoco instead of the IntegrationTest task. IMHO, If you want, feel free to proceed with the implementation—if not, I can take care of it on Monday 👍.

Thanks for reporting that improvement/bug!

In the ci config running unit and integration tests in dedicated phases should be fine. I would not do the clean before such that integration tests can use e.g.the compiled classes which have been created already before.

👆👆👆

cc: @pascalgrimaud , @murdos and @atomfrede

fabienpuissant added a commit to fabienpuissant/jhipster-lite that referenced this issue Dec 8, 2024
fabienpuissant added a commit to fabienpuissant/jhipster-lite that referenced this issue Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: bug 🐛 Something isn't working theme: gradle
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants