-
Notifications
You must be signed in to change notification settings - Fork 917
Run android integration tests in emulator #2036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
73bf06c
f1e081a
312a2da
bf28504
2aa838e
1b6b8c8
8466f39
b1c90a7
3bedbbe
2df3f24
d087994
3e84630
96e0f89
7aa1111
1c02773
90f1ad5
8886857
c96785a
385674e
da13905
f5aa0bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Android CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| api-level: [ 26, 28, 30, 33 ] | ||
| name: Rhino Android Tests | ||
| steps: | ||
| - name: Enable KVM | ||
| run: | | ||
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
| sudo udevadm control --reload-rules | ||
| sudo udevadm trigger --name-match=kvm | ||
| # we do not checkout test262 submodule or setup java in this build | ||
| - name: Check out Rhino | ||
| uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v4.2.2 | ||
| - name: Build and test for Android | ||
| uses: reactivecircus/android-emulator-runner@v2 | ||
| with: | ||
| api-level: ${{ matrix.api-level }} | ||
| arch: x86_64 | ||
| script: | | ||
| adb logcat -c || true # try to clear logs | ||
| mkdir -p it-android/build/reports # make dir | ||
| touch it-android/build/reports/emulator.log # create log file | ||
| chmod 777 it-android/build/reports/emulator.log # allow writing to log file | ||
| adb logcat >> it-android/build/reports/emulator.log & # pipe all logcat messages into log file as a background process | ||
| ./gradlew it-android:connectedCheck | ||
| - name: Upload results for Android | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| if: ${{ always() }} | ||
| with: | ||
| name: reports-android-sdk-${{ matrix.api-level }} | ||
| path: '*/build/reports' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,7 @@ rhino.iws | |
|
|
||
| .java-version | ||
| .kotlin | ||
|
|
||
| # android specific | ||
| android-sdk/ | ||
| local.properties | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #/usr/bin/env bash | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please move this file to the "it-android" directory so that the root directory doesn't get too full? Could you also make it executable (might need to mess around with Git -- usually if you "chmod a+x" the file Git will figure it out when you first add it). |
||
| # SDK downloader for android integration tests | ||
| export ANDROID_HOME=$PWD/android-sdk | ||
| mkdir -p $ANDROID_HOME/cmdline-tools | ||
|
|
||
| # Download and install command line tools | ||
| wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O tools.zip | ||
| unzip tools.zip -d $ANDROID_HOME/cmdline-tools | ||
| mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest | ||
|
|
||
| # Install SDK components | ||
| yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses | ||
| yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0" | ||
| # set in local properties | ||
| echo sdk.dir=./android-sdk >> local.properties | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Android integration tests | ||
|
|
||
| Rhino runs with some restrictions on android platform. This project builds a very minimalistic app/testframework to run | ||
| android tests either in an emulator or directly on your phone | ||
|
|
||
| ## Restrictions | ||
|
|
||
| ### Rhino runtime | ||
| - | ||
|
|
||
| - minSdk is 26 (see #1785 for background) | ||
| - runs only in intermreted mode | ||
| - not all features may be available (JavaAdapter, ...) | ||
|
|
||
| ### Emulator | ||
|
|
||
| - runs in emulated mode and may behave different, than a real android-device (JIT etc.) | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Tests | ||
|
|
||
| Write your tests in `src/main/assets/tests` in the same style as MozillaTestSuite | ||
|
|
||
| These are simple javascript tests. | ||
| (To write java-tests it is recommended to use android-studio.) | ||
|
|
||
| ### Running tests on github | ||
|
|
||
| This is done automatically on each PR (maybe changed as manual action, if it consumes too much resources) | ||
|
|
||
| ### Running tests locally | ||
|
|
||
| You need an Android SDK installed | ||
|
|
||
| - Either install Android-Studio with SDK https://developer.android.com/about/versions/14/setup-sdk | ||
|
|
||
| make sure that your `ANDROID_HOME` enviroment is set up properly | ||
| - Or use the provided script in `<RHINO_ROOT>/install-android-sdk` | ||
|
|
||
| This will install the SDK in `<RHINO_ROOT>/android-sdk` and register it in the `local.properties` for this gradle | ||
| build only. (This is the best option, if you do not want to mess up your system) | ||
|
|
||
| <b>Note:</b> The script will automatically accept all license terms! | ||
|
|
||
| Use `<RHINO_ROOT>/run-android-tests-locally.sh` to start an emulator in docker/podman, run the tests and install the | ||
| APK. | ||
|
|
||
| This will download an emulator based on https://github.com/budtmo/docker-android and you can access the emulated phone | ||
| on http://localhost:6080 | ||
|
|
||
| <b>Note:</b> The emulator will not terminate automatically. You will need to remove it from your docker/podman manually | ||
|
|
||
| ### Debugging and troubleshooting | ||
|
|
||
| - `./gradlew it-android:connectedAndroidTest` will try to run the tests automatically on the connected android device | ||
| - `./android-sdk/platform-tools/adb logcat` get logs from the device | ||
| - `./android-sdk/platform-tools/adb devices` list devices | ||
| - `./android-sdk/platform-tools/adb disconnect` disconnect devices | ||
| - `./android-sdk/platform-tools/adb connect localhost:5555` reconnect to emulator | ||
| - `docker rm -f android-container` or `podman rm -f android-container` remove the container | ||
|
|
||
| ### Running tests on your phone | ||
|
|
||
| You need an Android SDK and an Android phone of course. (iPhone will not work here) | ||
|
|
||
| - open your settings and enable `wireless debugging` | ||
| - select `pari device with pariing code` | ||
| - run `./android-sdk/platform-tools/adb pair HOST:PORT PAIRING_CODE` | ||
| - run `./android-sdk/platform-tools/adb connect HOST:PORT` (Note: The port is different from the pairing port) | ||
| - check `./android-sdk/platform-tools/adb devices`, if your device is connected | ||
| - run `./gradlew it-android:connectedAndroidTest` to run your tests | ||
| - or run `./gradlew it-android:installDebug` to deploy the app on your phone | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| buildscript { | ||
| repositories { | ||
| gradlePluginPortal() | ||
| google() | ||
| mavenCentral() | ||
| mavenLocal() | ||
| } | ||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:8.9.3' | ||
| } | ||
| } | ||
|
|
||
| plugins { | ||
| id 'rhino.spotless-conventions' | ||
| } | ||
|
|
||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| spotless { | ||
| java { | ||
| target "src/*/java/**/*.java" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // read the (android specific) local.properties file | ||
| def localPropertiesFile = rootProject.file("local.properties"); | ||
| Properties localProperties = new Properties() | ||
| if (localPropertiesFile.exists()) { | ||
| localProperties.load(localPropertiesFile.newDataInputStream()) | ||
| } | ||
|
|
||
| if (!System.getenv("ANDROID_HOME") && !localProperties.get("sdk.dir")) { | ||
| System.out.println("No Android SDK found. Skipping build") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skip android build for users, that do not have a SDK installed |
||
| } else { | ||
| apply plugin: 'com.android.application' | ||
|
|
||
| android { | ||
| namespace = "org.mozilla.javascript.android" | ||
|
|
||
| compileSdkVersion 33 | ||
| defaultConfig { | ||
| minSdk = 26 | ||
| targetSdk = 33 | ||
rPraml marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
|
|
||
| } | ||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_11 | ||
| targetCompatibility JavaVersion.VERSION_11 | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // To test against other versions, replace the dependencies by | ||
| implementation 'org.mozilla:rhino:1.7.15' | ||
| //implementation project(':rhino') | ||
|
|
||
| /*implementation project(':examples') | ||
| implementation project(':rhino-engine') | ||
| implementation project(':rhino-tools') | ||
| implementation project(':rhino-xml')*/ | ||
|
|
||
| testImplementation 'junit:junit:4.13.2' | ||
| androidTestImplementation 'androidx.test:runner:1.7.0' | ||
| androidTestImplementation 'androidx.test.ext:junit:1.3.0' | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.mozilla.javascript.android.test; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import android.content.Context; | ||
| import android.util.Log; | ||
| import androidx.test.platform.app.InstrumentationRegistry; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
| import org.mozilla.javascript.android.TestCase; | ||
|
|
||
| /** | ||
| * Simple testcase runner, that runs all Testcases provided by estCase.getTestCases. | ||
| * | ||
| * @author Roland Praml | ||
| */ | ||
| @RunWith(Parameterized.class) | ||
| public class RhinoTest { | ||
rPraml marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Parameterized.Parameter(value = 0) | ||
| public TestCase testCase; | ||
|
|
||
| @Test | ||
| public void test() { | ||
| String s = testCase.run(); | ||
| Log.i(testCase.toString(), s); | ||
| assertTrue(s.contains("success")); | ||
| } | ||
|
|
||
| @Parameterized.Parameters(name = "{index}, js={0}") | ||
| public static Collection<Object[]> suiteValues() throws IOException { | ||
| List<Object[]> result = new ArrayList<Object[]>(); | ||
| Context androidContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
| for (TestCase testCase : TestCase.getTestCases(androidContext)) { | ||
| result.add(new Object[] {testCase}); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application android:label="Rhino-Test"> | ||
| <activity android:name="MainActivity" android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
| </manifest> |
Uh oh!
There was an error while loading. Please reload this page.