BitriseでのDetoxテストの実行
Detoxは、React Nativeで構築されたモバイルアプリ向けのグレーボックスE2Eテストおよび自動化ライブラリです。iOSとAndroidの両方のアプリをサポートしています。Bitrise上にReact Nativeアプリがある場合、Detoxテストを実行できます。
開始する前にClick to copy link
Detoxの実行には、次のも のが必要です:
- macOS(El Capitan 10.11以降)を搭載したMac。
- Xcodeのコマンドラインツールを含むXcode 8.3以降。
- 動作するReact Nativeアプリ。
プロジェクトにDetoxをインストールしてセットアップします。Homebrew、Node.js、applesimutilsに加えて、Detoxのコマンドラインツールをインストールする必要があります。プロジェクトにDetoxを追加し、Detoxテストをローカルで作成して実行します。Androidアプリを使用している場合は、初期セットアッププロセスの後にこのガイドを参照してください。
完了したら、BitriseでDetoxを設定したプロジェクトをテストできます。
Detoxテストを実行するClick to copy link
-
package.jsonファイルのdetoxセクション内、または別のDetox設定ファイルでリリースデバイスの設定を作成します。Detoxの設定方法の詳細については、ドキュメントプロジェクトのセットアップを確認してください。例:
"detox": {"configurations": {"ios.sim.debug": {"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/SampleProjectReactNative.app","build": "xcodebuild -project ios/SampleProjectReactNative.xcodeproj -scheme SampleProjectReactNative -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -UseNewBuildSystem=NO","type": "ios.simulator","name": "iPhone 8"},"ios.sim.release": {"binaryPath": "ios/build/Build/Products/Release-iphonesimulator/SampleProjectReactNative.app","build": "xcodebuild -project ios/SampleProjectReactNative.xcodeproj -scheme SampleProjectReactNative -configuration Release -sdk iphonesimulator -derivedDataPath ios/build -UseNewBuildSystem=NO","type": "ios.simulator","name": "iPhone 8"}}, -
bitrise.ioでプロジェクトに移動し、Workflow Editorを開きます。
-
使用するWorkflowに切り替えます。
-
WorkflowにRun npm commandStepを追加します。
-
npm command with arguments to run入力を使用して、DetoxのCLIとReact Native CLIをインストールします:
install -g detox-cliinstall -g react-native-cli -
テストランナーをインストールします。
たとえば、サンプルアプリでは、
yarnStepを使用してインストールされたmochaを使用しています。yarnの依存関係をインストールするには、The yarn command to run入力の値をinstallに設定するだけです。 -
必要なユーティリティをインストールしてDetoxを実行するために、ScriptStepを追加します。
#!/bin/bash# applesimutils is a collection of utils for Apple simulatorsbrew tap wix/brewbrew install applesimutils# we are building and testing a release device configurationdetox build --configuration ios.sim.releasedetox test --configuration ios.sim.release --cleanupもちろん、モジュール性を保つために、これらの各コマンドを個別のScript Stepsに配置することもできます。
-
ビルドを実行します。
ビルドが失敗した場合は、bitrise.ymlのサンプルファイルを確認してください:
---
workflows:
primary:
steps:
- activate-ssh-key: {}
- git-clone:
inputs:
- clone_depth: ''
title: Git Clone Repo
- yarn:
inputs:
- command: install
- npm:
inputs:
- command: install -g detox-cli
title: Install Detox CLI
- script:
inputs:
- content: |-
#!/bin/bash
brew tap wix/brew
brew install applesimutils
detox build --configuration ios.sim.release
detox test --configuration ios.sim.release --cleanup
title: Detox - Build and Test Release App
- deploy-to-bitrise-io: {}
DetoxテストのトラブルシューティングClick to copy link
BitriseでDetoxの使用に問題がある場合は、テストを実行する前にDetoxパッ ケージ全体を再ビルドすることをお勧めします。
そのためには、Bitriseビルドで次のコマンドを実行します:
`npm rebuild detox`
それでもDetoxテストが失敗またはハングする場合は、サポートまでお問い合わせください。