How to export junit test report to Test Reports dashboard (Flutter)

Hi,
I would like to use Test Reports dashboard in my Flutter build workflow, but I’m unable to correctly export a junit test report.

I have a following step:

    - script@1.1.5:
        inputs:
        - content: |
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x

            brew tap dart-lang/dart
            brew install dart # dart for junitreport

            cd $BITRISE_SOURCE_DIR/$BITRISE_FLUTTER_PROJECT_LOCATION
            mkdir tests
            flutter pub pub global activate junitreport
            export PATH="$PATH":"$HOME/.pub-cache/bin"
            flutter test --machine | tojunit > $BITRISE_SOURCE_DIR/$BITRISE_FLUTTER_PROJECT_LOCATION/tests/TEST-report.xml
    - deploy-to-bitrise-io@1.4.2:
        inputs:
        - deploy_path: "$BITRISE_FLUTTER_PROJECT_LOCATION/tests"

This runs flutter tests and exports the results to TEST-report.xml (junit file).

In logs I can see that deploy executes with success:

Deploying the content of the Deploy directory separately
List of files to deploy
- /Users/vagrant/git/mobile/app/tests/TEST-report.xml
Deploying files
Uploading file: /Users/vagrant/git/app/employee/tests/TEST-report.xml
creating artifact
  file size: 3608B
uploading artifact
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3608    0     0  100  3608      0  13550 --:--:-- --:--:-- --:--:-- 13563
finishing artifact
is_enable_public_page is set, but public download isn't allowed for this type of file
Success
You can find the Artifact on Bitrise, on the Build's page: https://app.bitrise.io/build/8aca429a3e5e3c2f
Upload test results
- uploading (0) test results
Success

However, TEST-results.xml file is not recognized as test result. Is there any way to manually set this file as a source for tests results?

Example build slug: 8aca429a3e5e3c2f

Ok, I found a partial solution myself. One thing I miss is the step-info.json file. Is there any way to generate it or mock it?

The directory where test reports should go is defined here as $BITRISE_TEST_DEPLOY_DIR. So I export my test report as follows:

#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
# set -x

brew tap dart-lang/dart
brew install dart

cd $BITRISE_SOURCE_DIR/$BITRISE_FLUTTER_PROJECT_LOCATION
flutter pub pub global activate junitreport
export PATH="$PATH":"$HOME/.pub-cache/bin"
TEST_RESULT=`flutter test --machine | tojunit`
mkdir $BITRISE_TEST_DEPLOY_DIR/test_result123456/
echo $TEST_RESULT > $BITRISE_TEST_DEPLOY_DIR/test_result123456/TEST-report.xml
touch $BITRISE_TEST_DEPLOY_DIR/test_result123456/step-info.json # how to generate it?

Hi @dominik.roszkowski,

Sorry for staying silent on this until now! Great progress on this, good job :slight_smile:
Can you send us the build URL related to your latest attempts at this?

A step-info.json should automatically be generated, as long as the $BITRISE_TEST_DEPLOY_DIR isn’t empty.

1 Like

I’m not sure how does this work with an ordinary console step. Now my step does not produce step-info.json in BITRISE_TEST_DEPLOY_DIR. I discovered while studying Xcode and Android unit test steps that you have golang utilities to create and export this file e.g. here. Can I use them from shell script?

I also tried to modify current flutter test step to produce correct artifacts but with no success. You can take a look at my trial here.

One of my last successful builds with trial to upload tests is here: Bitrise - Mobile Continuous Integration and Delivery - iOS & Android Build Automation. Take a look at the step Flutter Test > Junit, where at the moment I try to copy test report to BITRISE_TEST_DEPLOY_DIR subdirectory:

brew tap dart-lang/dart
brew install dart

cd $BITRISE_SOURCE_DIR/$BITRISE_FLUTTER_PROJECT_LOCATION
flutter pub pub global activate junitreport
export PATH="$PATH":"$HOME/.pub-cache/bin"
TEST_RESULT=`flutter test --machine | tojunit`
mkdir $BITRISE_TEST_DEPLOY_DIR/test_result123456/
echo $TEST_RESULT > $BITRISE_TEST_DEPLOY_DIR/test_result123456/TEST-report.xml

Of course this does not work but I wanted to check what happens if I provide empty step-info.json file.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.