How to keep the test report of multiple gradle test tasks within the same job?

this is what my .yml file looks like:

image: openjdk:11

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false -Djava.security.egd=file:/dev/./urandom"
  DOCKER_TLS_CERTDIR: ""

build_custom_scripts:
  script:
    - ./gradlew test --tests=MainTest.testIsOddNumber
    - ./gradlew test --tests=MainTest.testIsInAlphabeticalOrder
  artifacts:
    when: always
    paths:
      - build/test-results/test/TEST-*.xml
    reports:
      junit: build/test-results/test/TEST-*.xml

currently, in the test report, l only see the second test. obviously the file is overwritten for the second gradlew test task. but l want to retain the content of the report from the previous tasks. how do l do that?

You can specify multiple tests filters in a single step
./gradlew test --tests=MainTest.testIsOddNumber --tests=MainTest.testIsInAlphabeticalOrder

I am aware of that. l assume, you know that doesn’t answer my question…i need to execute multiple gradle test tasks within a job.

I know your problem is that the second gradlew execution overwrites the test results files, because the file names are generated per test task and per Class.
The first execution generates a file TEST-com.example.project.MainTest.xml with content from testcase testIsOddNumber only. The second execution overwrite the file with testcase testIsInAlphabeticalOrder, because the test task and Class is the same. And this is how Gradle JUnit works. My first answer actually solves your problem from your example, because that way you can limit the tests from single Class which you execute and have the output together. Otherwise unless you move your tests to dedicated Classes there is no other way around it.

ok, thank you very much, that actually clears some air. let me restructure what l’m trying to do. I have multiple test classes and for some reason l cant test them all at once and what i found works, even tho quite dirty, is the following:

  • ./gradlew test --tests A*Test --tests B**Test
  • ./gradlew test --tests C*Test --tests D**Test

the double asterisk is supposed to be single. Looks like asterisk is a special character and i didnt know how to escape it. back to my problem, obviously the current unit test report contains only information from the second gradle task above because the test report from the previous task is being overwritten. how can l have a unit test report or multiple unit reports covering the classes in both tasks? maybe copy the content of the previous unittest report to another file or something before the second one overwrites it?

In that case you should have 4 files, one per Class. And all should be picked up by GitLab.
Could you please past here your definition of test task from build.gradle? You can paste code between 3 backticks like this:

```
some * * * * code
```

i dont have four classes, l have a lot more. The asterisk basically is like a regex. In the above example, the first task executes hundreds of test classes that start with “A” and end with “Test” and also same with “B”. and the second task takes care of all the test classes starting with “C” and “D”. This actually works. all the tests are executed. But , in the junit report, l only see results from classes starting with C and D, unsurprisingly…

All right, so after little digging I found out that Gradle actually removes all files from the destination directory to ‘remove any old or deprecated’ test results.
So the solution here would be pretty simple. After each gradle execution, move/zip/tar content from the test-results directory somewhere else and after you are done move/unzip/untar all the previous files back to the test-results directory.

Note on a side, GitLab has a 20MB limit on reports, but hopefully yours aren’t bigger :slight_smile:

1 Like

thank you! will follow that suggestion…