Skip to content

Commit

Permalink
instrumentation tests are executed with BUCK
Browse files Browse the repository at this point in the history
Summary:Added ability to run instrumentation tests with BUCK.

This change uses BUCK to build and run instrumentation tests facebook style.
The gains are that we can execute the same tests internally at FB and in OSS.
Also running tests not via graddle:connect command is 1.5 minutes faster.

I'll keep keep an eye on stability Gradle and BUCK builds for a while.
Closes facebook#6176

Differential Revision: D2999878

Pulled By: bestander

fb-gh-sync-id: d715ba231769e57100685a1256f2e530c589921c
shipit-source-id: d715ba231769e57100685a1256f2e530c589921c
  • Loading branch information
bestander authored and Facebook Github Bot 6 committed Mar 2, 2016
1 parent 4654b34 commit f827f7b
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 83 deletions.
2 changes: 1 addition & 1 deletion ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ android {
}

buildConfigField 'boolean', 'IS_INTERNAL_BUILD', 'false'
testApplicationId "com.facebook.react.tests"
testApplicationId "com.facebook.react.tests.gradle"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
6 changes: 3 additions & 3 deletions ReactAndroid/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.react.tests"
package="com.facebook.react.tests.gradle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:targetSdkVersion="7" />
Expand All @@ -12,8 +12,8 @@

<application>
<activity
android:name="com.facebook.react.testing.ReactAppTestActivity"
android:theme="@style/Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen"
android:name="com.facebook.react.testing.ReactAppTestActivity"
android:theme="@style/Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen"
/>
</application>
</manifest>
66 changes: 0 additions & 66 deletions ReactAndroid/src/androidTest/BUCK_temp

This file was deleted.

5 changes: 5 additions & 0 deletions ReactAndroid/src/androidTest/assets/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
android_resource(
name = 'assets',
assets = '.',
visibility = ['PUBLIC'],
)
24 changes: 24 additions & 0 deletions ReactAndroid/src/androidTest/buck-runner/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.react.tests">

<supports-screens android:anyDensity="true" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- needed for screenshot tests -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application>
<uses-library android:name="android.test.runner" />
<activity
android:name="com.facebook.react.testing.ReactAppTestActivity"
android:theme="@style/Theme.ReactNative.AppCompat.Light.NoActionBar.FullScreen">
</activity>
</application>

<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.facebook.react.tests"
android:label="Buck runs instrumentation tests"/>

</manifest>
23 changes: 23 additions & 0 deletions ReactAndroid/src/androidTest/buck-runner/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include_defs('//ReactAndroid/DEFS')

# We are running instrumentation tests in simple mode: app code and instrumentation are in the same APK
# Currently you need to run these commands to execute tests:
#
# node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/assets/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
# gradle :ReactAndroid:packageReactNdkLibsForBuck
# buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests
# ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests
android_binary(
name = 'instrumentation-tests',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:debug',
deps = [
react_native_integration_tests_target('java/com/facebook/react/tests:tests'),
react_native_integration_tests_target('assets:assets'),
react_native_target('jni/prebuilt:reactnative-libs'),
react_native_target('jni/prebuilt:android-jsc'),
react_native_dep('libraries/soloader/java/com/facebook/soloader:soloader'),
react_native_target('java/com/facebook/react/devsupport:devsupport'),
],
)

4 changes: 0 additions & 4 deletions ReactAndroid/src/androidTest/buildBundle.sh

This file was deleted.

24 changes: 15 additions & 9 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,29 @@ test:
# starting emulator in advance because it takes very long to boot
- $ANDROID_HOME/tools/emulator -avd testAVD -no-skin -no-audio -no-window:
background: true
# assemble done separately because it requires quite a lot of memory and also gives time for emulator to load
- ./gradlew :ReactAndroid:assembleDebug -PdisablePreDex -Pjobs=1:
timeout: 360
- source scripts/circle-ci-android-setup.sh && waitForAVD

override:
# buck tests
- buck/bin/buck test ReactAndroid/src/test/... --config build.threads=1
# build app
- buck/bin/buck build ReactAndroid/src/main/java/com/facebook/react
- buck/bin/buck build ReactAndroid/src/main/java/com/facebook/react/shell
# temp, we can't run instrumentation tests yet
- buck/bin/buck build ReactAndroid/src/androidTest/java/com/facebook/react/tests

# unit tests
- ./gradlew :ReactAndroid:testDebugUnitTest -PdisablePreDex
- buck/bin/buck test ReactAndroid/src/test/... --config build.threads=1

# instrumentation tests
# compile native libs with Gradle script
- ./gradlew :ReactAndroid:packageReactNdkLibsForBuck -PdisablePreDex -Pjobs=1:
timeout: 360
# build JS bundle for instrumentation tests
- node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/assets/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
# run tests on the emulator
# build test APK
- buck/bin/buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
# run installed apk with tests
- ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests

# Deprecated: run tests with Gradle, we keep them for a while to compare performance
- ./gradlew :ReactAndroid:testDebugUnitTest -PdisablePreDex
- ./gradlew :ReactAndroid:connectedAndroidTest -PdisablePreDex --stacktrace --info:
timeout: 360

Expand All @@ -67,6 +71,8 @@ test:
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
- find . -type f -regex ".*/build/test-results/debug/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
- find . -type f -regex ".*/outputs/androidTest-results/connected/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
# TODO circle does not understand Buck's report, maybe need to transform xml slightly
#- find . -type f -regex ".*/buck-out/gen/ReactAndroid/src/test/.*/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;

deployment:
website:
Expand Down
52 changes: 52 additions & 0 deletions scripts/run-android-instrumentation-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"

# clear the logs
adb logcat -c

# run tests and check output
python - $1 << END
import re
import subprocess as sp
import sys
import threading
import time
done = False
test_app = sys.argv[1]
def update():
# prevent CircleCI from killing the process for inactivity
while not done:
time.sleep(5)
print "Running in background. Waiting for 'adb' command reponse..."
t = threading.Thread(target=update)
t.dameon = True
t.start()
def run():
sp.Popen(['adb', 'wait-for-device']).communicate()
p = sp.Popen('adb shell am instrument -w %s/android.support.test.runner.AndroidJUnitRunner' % test_app,
shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
return p.communicate()
success = re.compile(r'OK \(\d+ tests\)')
stdout, stderr = run()
done = True
print stderr
print stdout
if success.search(stderr + stdout):
sys.exit(0)
else:
# dump the logs
sp.Popen(['adb', 'logcat', '-d']).communicate()
sys.exit(1) # make sure we fail if the test failed
END

RETVAL=$?

exit $RETVAL

0 comments on commit f827f7b

Please sign in to comment.