Skip to content

Commit

Permalink
Merge branch 'master' into robolectric-4.11.x
Browse files Browse the repository at this point in the history
And increment version to 4.11-beta-2
  • Loading branch information
brettchabot committed Oct 19, 2023
2 parents 3d992b9 + 6e4a3b4 commit 8ce1732
Show file tree
Hide file tree
Showing 122 changed files with 4,023 additions and 571 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/copybara_build_and_test.yml
@@ -0,0 +1,40 @@
name: Copybara tests

on:
pull_request:
branches: [ google ]

permissions:
contents: read

jobs:
copybara-tests:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- uses: gradle/gradle-build-action@v2

- name: Build
run: |
SKIP_ERRORPRONE=true SKIP_JAVADOC=true \
./gradlew assemble testClasses --parallel --stacktrace --no-watch-fs
- name: Integration tests
run: |
# Only run integration tests on Copybara PRs
(cd integration_tests && \
SKIP_ERRORPRONE=true SKIP_JAVADOC=true \
../gradlew test --info --stacktrace --continue --parallel --no-watch-fs \
-Drobolectric.alwaysIncludeVariantMarkersInTestName=true \
-Drobolectric.enabledSdks=34 \
-Dorg.gradle.workers.max=2 \
-x :integration_tests:nativegraphics:test \
)
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Expand Up @@ -2,12 +2,12 @@ name: Tests

on:
push:
branches: [ master, 'robolectric-*.x' ]
branches: [ master, 'robolectric-*.x', 'google' ]
paths-ignore:
- '**.md'

pull_request:
branches: [ master, google ]
branches: [ master ]
paths-ignore:
- '**.md'

Expand Down Expand Up @@ -35,15 +35,15 @@ jobs:
- name: Build
run: |
SKIP_ERRORPRONE=true SKIP_JAVADOC=true \
./gradlew clean assemble testClasses --parallel --stacktrace --no-watch-fs
./gradlew assemble testClasses --parallel --stacktrace --no-watch-fs
unit-tests:
runs-on: ubuntu-22.04
needs: build
strategy:
fail-fast: false
matrix:
api-versions: [ '19,21,22', '23,24,25', '26,27,28', '29,30,31', '32,33' ]
api-versions: [ '19,21,34', '22,23,33', '24,25,32', '26,27,28', '29,30,31', ]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@

Robolectric is the industry-standard unit testing framework for Android. With Robolectric, your tests run in a simulated Android environment inside a JVM, without the overhead and flakiness of an emulator. Robolectric tests routinely run 10x faster than those on cold-started emulators.

Robolectric supports running unit tests for *17* different versions of Android, ranging from Jelly Bean (API level 16) to TIRAMISU (API level 33).
Robolectric supports running unit tests for *15* different versions of Android, ranging from KitKat (API level 19) to U (API level 34).

## Usage

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/groovy/AndroidSdk.groovy
Expand Up @@ -15,12 +15,12 @@ class AndroidSdk implements Comparable<AndroidSdk> {
static final S = new AndroidSdk(31, "12", "7732740");
static final S_V2 = new AndroidSdk(32, "12.1", "8229987");
static final TIRAMISU = new AndroidSdk(33, "13", "9030017");

static final U = new AndroidSdk(34, "14", "10818077");

static final List<AndroidSdk> ALL_SDKS = [
KITKAT,
LOLLIPOP, LOLLIPOP_MR1, M, N, N_MR1, O, O_MR1, P, Q, R, S, S_V2,
TIRAMISU
TIRAMISU, U
]

static final MAX_SDK = Collections.max(ALL_SDKS)
Expand Down
Expand Up @@ -2,6 +2,7 @@ package org.robolectric.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test

public class AndroidProjectConfigPlugin implements Plugin<Project> {
@Override
Expand Down Expand Up @@ -63,5 +64,11 @@ public class AndroidProjectConfigPlugin implements Plugin<Project> {
}
}
}

// Only run tests in the debug variant. This is to avoid running tests twice when `./gradlew test` is run at the top-level.
project.tasks.withType(Test) {
onlyIf { variantName.toLowerCase().contains('debug') }
}
}
}

2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,3 +1,3 @@
thisVersion=4.11-beta-1
thisVersion=4.11-beta-2
android.useAndroidX=true
kotlin.stdlib.default.dependency=false
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
@@ -1,6 +1,6 @@
[versions]
robolectric-compat = "4.10.2"
robolectric-nativeruntime-dist-compat = "1.0.1"
robolectric-nativeruntime-dist-compat = "1.0.2"

# https://developer.android.com/studio/releases
android-gradle = "8.1.2"
Expand Down Expand Up @@ -65,7 +65,7 @@ truth = "1.1.5"
# https://github.com/unicode-org/icu/releases
icu4j = "73.2"

jacoco = "0.8.10"
jacoco = "0.8.11"

# https://github.com/javaee/javax.annotation/tags
javax-annotation-api = "1.3.2"
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/agp/build.gradle
Expand Up @@ -4,12 +4,12 @@ apply plugin: 'com.android.library'
apply plugin: AndroidProjectConfigPlugin

android {
compileSdk 33
compileSdk 34
namespace 'org.robolectric.integrationtests.agp'

defaultConfig {
minSdk 19
targetSdk 33
targetSdk 34
}

compileOptions {
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/agp/testsupport/build.gradle
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdk 33
compileSdk 34
namespace 'org.robolectric.integrationtests.agp.testsupport'

defaultConfig {
minSdk 19
targetSdk 33
targetSdk 34
}

compileOptions {
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/androidx/AndroidManifest.xml
Expand Up @@ -5,7 +5,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.robolectric.integrationtests.androidx">
<uses-sdk
android:targetSdkVersion="29" />
android:targetSdkVersion="34" />

<application />

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/androidx/build.gradle
Expand Up @@ -4,12 +4,12 @@ apply plugin: 'com.android.library'
apply plugin: AndroidProjectConfigPlugin

android {
compileSdk 33
compileSdk 34
namespace 'org.robolectric.integrationtests.androidx'

defaultConfig {
minSdk 19
targetSdk 33
targetSdk 34
}

compileOptions {
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/androidx_test/build.gradle
Expand Up @@ -6,12 +6,12 @@ apply plugin: AndroidProjectConfigPlugin
apply plugin: GradleManagedDevicePlugin

android {
compileSdk 33
compileSdk 34
namespace 'org.robolectric.integration.axt'

defaultConfig {
minSdk 19
targetSdk 33
targetSdk 34
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: 'true'
Expand All @@ -25,6 +25,9 @@ android {
testOptions {
unitTests {
includeAndroidResources = true
all {
systemProperty 'robolectric.graphicsMode', 'NATIVE'
}
}
}
sourceSets {
Expand Down
Expand Up @@ -4,7 +4,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.robolectric.integration.axt">
<uses-sdk android:targetSdkVersion="28"/>
<uses-sdk android:targetSdkVersion="34"/>

<uses-permission android:name="android.permission.READ_CONTACTS"/>

Expand Down
9 changes: 7 additions & 2 deletions integration_tests/androidx_test/src/main/AndroidManifest.xml
Expand Up @@ -2,14 +2,19 @@
<!--
Manifest for ATSL integration tests
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >

<uses-permission android:name="android.permission.READ_CONTACTS"/>

<application>
<activity android:name="org.robolectric.integrationtests.axt.EspressoActivity"
android:label="Activity Label"
android:exported="true" />
android:exported="true" >
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="org.robolectric.integrationtests.axt.EspressoScrollingActivity"
android:exported="true" />
<activity android:name="org.robolectric.integrationtests.axt.ActivityWithPlatformMenu"
Expand Down
Expand Up @@ -4,8 +4,8 @@
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>
android:minSdkVersion="19"
android:targetSdkVersion="34"/>

<application>
<activity android:name=".EspressoActivity" android:exported="true"/>
Expand Down
Expand Up @@ -13,7 +13,10 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.EditText;
Expand All @@ -30,6 +33,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.LooperMode;
import org.robolectric.annotation.LooperMode.Mode;
import org.robolectric.integration.axt.R;

/** Simple tests to verify espresso APIs can be used on both Robolectric and device. */
Expand Down Expand Up @@ -223,4 +228,16 @@ public void clickButton_after_swipeUp() {
activityScenario.onActivity(action -> assertThat(action.buttonClicked).isTrue());
}
}

@Test
@LooperMode(Mode.INSTRUMENTATION_TEST) // only instrumentation test mode has the correct behavior
public void onView_mainThread() {
new Handler(Looper.getMainLooper())
.post(
() ->
assertThrows(
IllegalStateException.class,
() -> onView(withId(R.id.edit_text)).perform(typeText("Some text."))));
Espresso.onIdle();
}
}
Expand Up @@ -4,8 +4,8 @@
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>
android:minSdkVersion="19"
android:targetSdkVersion="34"/>

<application>
<activity
Expand Down
Expand Up @@ -4,8 +4,8 @@
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>
android:minSdkVersion="19"
android:targetSdkVersion="34"/>

<application>
<activity
Expand Down
Expand Up @@ -4,13 +4,14 @@
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>
android:minSdkVersion="19"
android:targetSdkVersion="34"/>

<application>
<activity
android:name="org.robolectric.integrationtests.axt.IntentsTest$ResultCapturingActivity"
android:exported = "true"/>
android:exported = "true">
</activity>
</application>

<instrumentation
Expand Down
Expand Up @@ -4,8 +4,8 @@
package="org.robolectric.integrationtests.axt">

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="27"/>
android:minSdkVersion="19"
android:targetSdkVersion="34"/>

<application>
<activity android:name=".EspressoActivity" android:exported="true"/>
Expand Down
Expand Up @@ -10,6 +10,7 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Looper;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.R;
Expand Down Expand Up @@ -279,4 +280,15 @@ public void onActivityExceptionPropagated() {
}));
}
}

@Test
public void onActivity_runsOnMainLooperThread() {
try (ActivityScenario<TranscriptActivity> activityScenario =
ActivityScenario.launch(TranscriptActivity.class)) {
activityScenario.onActivity(
activity -> {
assertThat(Looper.getMainLooper().getThread()).isEqualTo(Thread.currentThread());
});
}
}
}
2 changes: 1 addition & 1 deletion integration_tests/ctesque/AndroidManifest.xml
Expand Up @@ -6,7 +6,7 @@
package="org.robolectric.integrationtests.ctesque">
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="27" />
android:targetSdkVersion="34" />

<application />

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/ctesque/build.gradle
Expand Up @@ -6,12 +6,12 @@ apply plugin: AndroidProjectConfigPlugin
apply plugin: GradleManagedDevicePlugin

android {
compileSdk 33
compileSdk 34
namespace 'org.robolectric.integrationtests.ctesque'

defaultConfig {
minSdk 19
targetSdk 33
targetSdk 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down

0 comments on commit 8ce1732

Please sign in to comment.