Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Builds your Android project with Gradle with the belonging AndroidTest variant.
<summary>Description</summary>

[This Step](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing) generates all the APKs you need to run instrumentation tests for your Android app: both an APK from your app and the belonging test APK, for example, `:app:assembleDemoDebug`, `:app:assembleDemoDebugAndroidTest`

### Configuring the Step
1. Add the **Project Location** which is the root directory of your Android project.
2. Set the **Module** you want to build. To see your available modules, open your project in Android Studio and go to **Project Structure** and see the list on the left.
Expand All @@ -29,7 +29,7 @@ Builds your Android project with Gradle with the belonging AndroidTest variant.

## 🧩 Get started

Add this step directly to your workflow in the [Bitrise Workflow Editor](https://devcenter.bitrise.io/steps-and-workflows/steps-and-workflows-index/).
Add this step directly to your workflow in the [Bitrise Workflow Editor](https://docs.bitrise.io/en/bitrise-ci/workflows-and-pipelines/steps/adding-steps-to-a-workflow.html).

You can also run this step directly with [Bitrise CLI](https://github.com/bitrise-io/bitrise).

Expand Down Expand Up @@ -61,9 +61,8 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris

We welcome [pull requests](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing/pulls) and [issues](https://github.com/bitrise-steplib/bitrise-step-android-build-for-ui-testing/issues) against this repository.

For pull requests, work on your changes in a forked repository and use the Bitrise CLI to [run step tests locally](https://devcenter.bitrise.io/bitrise-cli/run-your-first-build/).
For pull requests, work on your changes in a forked repository and use the Bitrise CLI to [run step tests locally](https://docs.bitrise.io/en/bitrise-ci/bitrise-cli/running-your-first-local-build-with-the-cli.html).

Learn more about developing steps:

- [Create your own step](https://devcenter.bitrise.io/contributors/create-your-own-step/)
- [Testing your Step](https://devcenter.bitrise.io/contributors/testing-and-versioning-your-steps/)
- [Create your own step](https://docs.bitrise.io/en/bitrise-ci/workflows-and-pipelines/developing-your-own-bitrise-step/developing-a-new-step.html)
42 changes: 25 additions & 17 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,48 @@ workflows:
- TEST_APP_BRANCH: maintenance
- TEST_APP_MODULE: app
- TEST_APP_VARIANT: DemoDebug
after_run:
- JDK_VERSION: 17
before_run:
- _run
- _check_outputs

test_two_steps_in_workflow:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/android-multiple-test-results-sample.git
- TEST_APP_BRANCH: maintenance
- TEST_APP_MODULE: app
- TEST_APP_VARIANT: DemoDebug
- JDK_VERSION: 17
before_run:
- _run
- _check_outputs
steps:
- path::./:
inputs:
- project_location: ./_tmp
- module: $TEST_APP_MODULE
- variant: $TEST_APP_VARIANT
- arguments: $GRADLE_ARGUMENTS --warn

test_library_module:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-Android-Modules-Sample.git
- TEST_APP_BRANCH: main
- TEST_APP_MODULE: feature:example1
- TEST_APP_VARIANT: debug
- GRADLE_ARGUMENTS: :app:assembleDebug # workaround for building a main app for a library module
after_run:
- JDK_VERSION: 21
before_run:
- _run
- _check_outputs

_run:
steps:
- script:
- set-java-version@1:
run_if: $.IsCI
inputs:
- content: |-
#!/usr/bin/env bash
set -ex
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo update-alternatives --set javac /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
envman add --key JAVA_HOME --value "/usr/lib/jvm/java-11-openjdk-amd64"
elif [[ "$OSTYPE" == "darwin"* ]]; then
jenv global 11 || jenv global 11.0
export JAVA_HOME="$(jenv prefix)"
envman add --key JAVA_HOME --value "$(jenv prefix)"
fi
- script:
- set_java_version: $JDK_VERSION
- script@1:
inputs:
- content: |-
#!/bin/env bash
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -138,6 +139,14 @@ func androidTestVariantPairs(module string, variantsMap gradle.Variants) (gradle
return variantPairs, nil
}

func isTestAPK(apkPath string) bool {
// Example names:
// app-debug-androidTest.apk
// app-debug-androidTest-20250904183958.apk (timestamped, when duplicate)
testArtifactRegexp := regexp.MustCompile(`(?i).*android[tT]est.*\.apk$`)
return testArtifactRegexp.MatchString(path.Base(apkPath))
}

func mainE(config Configs) error {
started := time.Now()

Expand Down Expand Up @@ -228,7 +237,7 @@ func mainE(config Configs) error {
var exportedAppArtifact string
var exportedTestArtifact string
for _, pth := range exportedArtifactPaths {
if strings.HasSuffix(strings.ToLower(path.Base(pth)), "androidtest.apk") {
if isTestAPK(pth) {
exportedTestArtifact = pth
} else {
exportedAppArtifact = pth
Expand Down
37 changes: 37 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,40 @@ func wantVariantFilterForAnotherApp() gradle.Variants {
want["another_app"] = []string{"AnotherDemoDebug", "AnotherDemoDebugAndroidTest"}
return want
}

func Test_isTestModule(t *testing.T) {
tests := []struct {
name string
apkPath string
want bool
}{
{
name: "test module apk",
apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
want: true,
},
{
name: "test module apk, lowercased",
apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidtest.apk",
want: true,
},
{
name: "test module apk with timestamp",
apkPath: "app/build/outputs/apk/androidTest/debug/app-debug-androidTest-20250904183958.apk",
want: true,
},
{
name: "non-test apk",
apkPath: "app/build/outputs/apk/debug/app-debug.apk",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := isTestAPK(tt.apkPath)
if got != tt.want {
t.Errorf("isTestModule() = %v, want %v", got, tt.want)
}
})
}
}