Home > Enterprise >  How to access Bitrise iOS test results from Swift DangerFile?
How to access Bitrise iOS test results from Swift DangerFile?

Time:10-24

I'm trying to implement danger-swift but I don't know where I can access test results and flag failing ones from Bitrise.

I'm using a plugin for danger-swift called DangerXCodeSummary but I don't know where Bitrise stores test results from xcode-test@2.

DangerFile:

import Danger
import DangerXCodeSummary
import Foundation

let danger = Danger()

let testReportPath = "??" // What's the path for the test results?
XCodeSummary(filePath: testReportPath).report()

Bitrise script:

...
UnitTests:
before_run:
- _ensure_dependencies
after_run:
- _add_build_result_to_pr
steps:
- xcode-test@2: {} # What's the file path for the test results?
- deploy-to-bitrise-io@1: {}
envs:
-   ots:
    is_expand: false
    BITRISE_PROJECT_PATH: MyApp.xcodeproj
- opts:
    is_expand: false
    BITRISE_SCHEME: AppTests
    description: Unit Tests running at every commit.
...

_add_build_result_to_pr:
steps:
- script@1:
    title: Commenting on the PR
    is_always_run: true
    inputs:
    - content: |-
        #!/usr/bin/env bash
        # fail if any commands fails
        set -e
        echo "################### DANGER ######################"
        echo "Install Danger"
        brew install danger/tap/danger-swift
        echo "Run danger"
        danger-swift ci
        echo "#################################################"

CodePudding user response:

You can see what outputs the step generates on the Workflow Editor UI, and alternatively in the Step's repository in step.yml. For Xcode Test step specifically: https://github.com/bitrise-steplib/steps-xcode-test/blob/deb39d7e9e055a22f33550ed3110fb3c71beeb79/step.yml#L287

Am I right that you're looking for the xcresult test output? If you are, you can read it from the BITRISE_XCRESULT_PATH environment variable (https://github.com/bitrise-steplib/steps-xcode-test/blob/deb39d7e9e055a22f33550ed3110fb3c71beeb79/step.yml#L296), which is the output of Xcode Test (once Xcode Test is finished, it sets this environment variable to the xcresult's path). Keep in mind this is in .xcresult format (the official Xcode test result format).

  • Related