Skip to content

Commit

Permalink
Merge pull request #238 from bugsnag/tms/build-apps
Browse files Browse the repository at this point in the history
Placeholder e2e tests for Android target
  • Loading branch information
twometresteve committed May 12, 2021
2 parents 2bf2be8 + 0ad49d0 commit 6ff97ec
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 10 deletions.
119 changes: 119 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,122 @@ steps:
- cd test/desktop
- bundle install
- bundle exec bugsnag-maze-runner

- label: ':android: Build Android test fixture for Unity 2017'
key: 'build-android-fixture-2017'
depends_on: 'build-artifacts'
timeout_in_minutes: 30
agents:
queue: opensource-mac-unity
env:
UNITY_VERSION: "2017.4.40f1"
plugins:
artifacts#v1.2.0:
download:
- Bugsnag.unitypackage
- Bugsnag-with-android-64bit.unitypackage
upload:
- test/mobile/features/fixtures/maze_runner/mazerunner_2017.4.40f1.apk
commands:
- ./test/mobile/features/scripts/build_fixture.sh
concurrency: 2
concurrency_group: 'unity-license'

- label: ':android: Run Android e2e tests for Unity 2017'
depends_on: 'build-android-fixture-2017'
timeout_in_minutes: 30
agents:
queue: opensource
plugins:
artifacts#v1.3.0:
download:
- "test/mobile/features/fixtures/maze_runner/mazerunner_2017.4.40f1.apk"
docker-compose#v3.3.0:
run: maze-runner
command:
- "--app=/app/features/fixtures/maze_runner/mazerunner_2017.4.40f1.apk"
- "--farm=bs"
- "--device=ANDROID_9_0"
- "--fail-fast"
concurrency: 9
concurrency_group: browserstack-app

- label: ':android: Build Android test fixture for Unity 2018'
key: 'build-android-fixture-2018'
depends_on: 'build-artifacts'
timeout_in_minutes: 30
agents:
queue: opensource-mac-unity
env:
UNITY_VERSION: "2018.4.34f1"
plugins:
artifacts#v1.2.0:
download:
- Bugsnag.unitypackage
- Bugsnag-with-android-64bit.unitypackage
upload:
- test/mobile/features/fixtures/maze_runner/mazerunner_2018.4.34f1.apk
commands:
- ./test/mobile/features/scripts/build_fixture.sh
concurrency: 2
concurrency_group: 'unity-license'

- label: ':android: Run Android e2e tests for Unity 2018'
depends_on: 'build-android-fixture-2018'
timeout_in_minutes: 30
agents:
queue: opensource
plugins:
artifacts#v1.3.0:
download:
- "test/mobile/features/fixtures/maze_runner/mazerunner_2018.4.34f1.apk"
docker-compose#v3.3.0:
run: maze-runner
command:
- "--app=/app/features/fixtures/maze_runner/mazerunner_2018.4.34f1.apk"
- "--farm=bs"
- "--device=ANDROID_9_0"
- "--fail-fast"
concurrency: 9
concurrency_group: browserstack-app

- label: ':android: Build Android test fixture for Unity 2019'
skip: Pending PLAT-6447
key: 'build-android-fixture-2019'
depends_on: 'build-artifacts'
timeout_in_minutes: 30
agents:
queue: opensource-mac-unity
env:
UNITY_VERSION: "2019.4.25f1"
plugins:
artifacts#v1.2.0:
download:
- Bugsnag.unitypackage
- Bugsnag-with-android-64bit.unitypackage
upload:
- test/mobile/features/fixtures/maze_runner/mazerunner_2019.4.25f1.apk
commands:
- ./test/mobile/features/scripts/build_fixture.sh
concurrency: 2
concurrency_group: 'unity-license'

- label: ':android: Run Android e2e tests for Unity 2019'
skip: Pending PLAT-6447
depends_on: 'build-android-fixture-2019'
timeout_in_minutes: 30
agents:
queue: opensource
plugins:
artifacts#v1.3.0:
download:
- "test/mobile/features/fixtures/maze_runner/mazerunner_2019.4.25f1.apk"
docker-compose#v3.3.0:
run: maze-runner
command:
- "--app=/app/features/fixtures/maze_runner/mazerunner_2019.4.25f1.apk"
- "--farm=bs"
- "--device=ANDROID_9_0"
- "--fail-fast"
concurrency: 9
concurrency_group: browserstack-app
62 changes: 62 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Mazerunner tests

E2E tests are implemented with our notifier testing tool [Maze runner](https://github.com/bugsnag/maze-runner),
which is a black-box test framework written in Ruby.

End to end tests are written in cucumber-style `.feature` files, and need Ruby-backed "steps" in order to know what
to run. The tests are located in the `features` subdirectories beneath [`test`](/test/).

There are separate sets of tests for the desktop and mobile targets.

## Mobile tests

### Building the test fixture

Building the mobile test fixtures currently assumes a macOS based Unity installation. To build any test fixture,
from the root of the repository, first build the notifier:
```
rake plugin:export
```
This will generate the following files:
* `Bugsnag.unitypackage`
* `Bugsnag-with-android-64bit.unitypackage`

#### Android

To build the Android test fixture:
```
UNITY_VERSION=2018.4.34f1 ./test/mobile/features/scripts/build_fixture.sh
```
Where `UNITY_VERSION` corresponds to the Unity installation path, e.g:
```
/Applications/Unity/Hub/Editor/2018.4.34f1/Unity.app/Contents/MacOS/Unity
```

This will generate a test fixture APK named according to the `UNITY_VERSION`, e.g:
```
./test/mobile/features/fixtures/maze_runner/mazerunner_2018.4.34f1.apk
```

### Running an end-to-end test

__Note: only Bugsnag employees can run the end-to-end tests for mobile targets.__ We have dedicated test infrastructure
and private BrowserStack credentials that can't be shared outside of the organization.

Remote tests can be run against real devices provided by BrowserStack. In order to run these tests, you need to set
the following environment variables:

- A BrowserStack App Automate Username: `BROWSER_STACK_USERNAME`
- A BrowserStack App Automate Access Key: `BROWSER_STACK_ACCESS_KEY`
- A path to a [BrowserStack local testing binary](https://www.browserstack.com/local-testing/app-automate): `MAZE_BS_LOCAL`

#### Android

1. `cd test/mobile`
1. Run `bundle install` if you haven't run end-to-end tests before
1. Check the contents of `Gemfile` to select the version of `maze-runner` to use
1. To run the tests:
```shell script
bundle exec maze-runner --app=./features/fixtures/maze_runner/mazerunner_2018.4.34f1.apk \
--farm=bs \
--device=ANDROID_9_0
```
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.6'
services:

maze-runner:
image: 855461928731.dkr.ecr.us-west-1.amazonaws.com/maze-runner-releases:latest-v5-cli
environment:
DEBUG:
BUILDKITE:
BUILDKITE_PIPELINE_NAME:
BROWSER_STACK_USERNAME:
BROWSER_STACK_ACCESS_KEY:
volumes:
- ./test:/app/test
- ./test/mobile/features/:/app/features
3 changes: 2 additions & 1 deletion test/desktop/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# definitions

ENV['BUGSNAG_APIKEY'] = 'a35a2a72bd230ac0aa0f52715bbdc6aa'

# Extract the test fixture app
unity_project_name = ENV['UNITY_PROJECT_NAME'] = "Mazerunner"
unity_test_project = "features/fixtures/maze_runner/#{unity_project_name}.app"

`cd features/fixtures && tar -xzf #{unity_project_name}-#{ENV['UNITY_VERSION']}.app.zip`

# Scenario hooks
Expand Down
2 changes: 1 addition & 1 deletion test/mobile/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gem "bugsnag-maze-runner", git: "https://github.com/bugsnag/maze-runner", tag: "v5.0.1"
gem "bugsnag-maze-runner", git: "https://github.com/bugsnag/maze-runner", tag: "v5.1.0"
8 changes: 3 additions & 5 deletions test/mobile/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
GIT
remote: https://github.com/bugsnag/maze-runner
revision: 9aaf72b51c4f340f9d4901497752af70f526543f
tag: v5.0.1
revision: f7536f3128462c5e56963b6c75372b3e96243823
tag: v5.1.0
specs:
bugsnag-maze-runner (5.0.1)
bugsnag-maze-runner (5.1.0)
appium_lib (~> 11.2.0)
boring (~> 0.1.0)
cucumber (~> 3.1.2)
cucumber-expressions (~> 6.0.0)
curb (~> 0.9.6)
Expand All @@ -28,7 +27,6 @@ GEM
faye-websocket (~> 0.11.0)
selenium-webdriver (~> 3.14, >= 3.14.1)
backports (3.21.0)
boring (0.1.0)
builder (3.2.4)
childprocess (3.0.0)
cucumber (3.1.2)
Expand Down
2 changes: 1 addition & 1 deletion test/mobile/features/fixtures/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ Assets/Standard\ Assets/Bugsnag/BugsnagBehaviour.cs
# Builds
*.apk
*.unitypackage

maze_runner
50 changes: 50 additions & 0 deletions test/mobile/features/fixtures/Assets/Editor/Builder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Linq;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;

public class Builder : MonoBehaviour
{
// Generates AndroidBuild/MyApp.apk
public static void AndroidBuild()
{
Debug.Log("Building Android app...");
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.bugsnag.mazerunner");
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
var opts = CommonOptions("mazerunner.apk");
opts.target = BuildTarget.Android;

var result = BuildPipeline.BuildPlayer(opts);

Debug.Log("Result: " + result);
}

private static BuildPlayerOptions CommonOptions(string outputFile)
{
var paths = new string[] { "Assets/Scenes/SampleScene.unity", "Assets/Scenes/OtherScene.unity" };
var newScenes = new EditorBuildSettingsScene[]
{
new EditorBuildSettingsScene()
{
path = paths[0],
enabled = true
},
new EditorBuildSettingsScene()
{
path = paths[1],
enabled = true
}
};

EditorBuildSettings.scenes = newScenes;

BuildPlayerOptions opts = new BuildPlayerOptions();
opts.scenes = paths;
opts.locationPathName = Application.dataPath + "/../" + outputFile;
opts.options = BuildOptions.None;

return opts;
}
}
#endif
11 changes: 11 additions & 0 deletions test/mobile/features/fixtures/Assets/Editor/Builder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Parky">
<application android:usesCleartextTraffic="true" android:label="@string/app_name" android:icon="@mipmap/app_icon">
package="com.bugsnag.mazerunner">
<application android:usesCleartextTraffic="true" android:label="@string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
47 changes: 47 additions & 0 deletions test/mobile/features/scripts/build_fixture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

if [ -z "$UNITY_VERSION" ]
then
echo "UNITY_VERSION must be set"
exit 1
else
export PATH="/Applications/Unity/Hub/Editor/$UNITY_VERSION/Unity.app/Contents/MacOS:$PATH"
echo "\`which Unity\`=`which Unity`"
fi

pushd "${0%/*}"
script_path=`pwd`
popd

pushd "$script_path/../fixtures"

# Run unity and immediately exit afterwards, log all output, disable the
# package manager (we just don't need it and it slows things down)
DEFAULT_CLI_ARGS="-quit -batchmode -logFile unity.log -noUpm"
project_path=`pwd`/maze_runner

# Creating a new project in the MyProject directory
Unity $DEFAULT_CLI_ARGS -createProject $project_path

# Installing the Bugsnag package
echo "Importing Bugsnag.unitypackage into $project_path"
Unity $DEFAULT_CLI_ARGS -projectPath $project_path -importPackage $script_path/../../../../Bugsnag.unitypackage
RESULT=$?
if [ $RESULT -ne 0 ]; then exit $RESULT; fi

echo "Importing Bugsnag-with-android-64bit.unitypackage into $project_path"
Unity $DEFAULT_CLI_ARGS -projectPath $project_path -importPackage $script_path/../../../../Bugsnag-with-android-64bit.unitypackage
RESULT=$?
if [ $RESULT -ne 0 ]; then exit $RESULT; fi

cp -r Assets/Scenes maze_runner/Assets/
cp -r Assets/Scripts maze_runner/Assets/
cp Assets/Editor/Builder.cs maze_runner/Assets/Scripts/
cp Assets/Plugins/Android/AndroidManifest.xml maze_runner/Assets/Plugins/Android

# Running a custom script - must reference a static method
Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod Builder.AndroidBuild
RESULT=$?
if [ $RESULT -ne 0 ]; then exit $RESULT; fi

mv $project_path/mazerunner.apk $project_path/mazerunner_$UNITY_VERSION.apk

0 comments on commit 6ff97ec

Please sign in to comment.