Skip to content

Commit f3f00fc

Browse files
committed
Update to AndroidX Test 1.3.0-alpha03
Also add espresso accessibility sample.
1 parent 7e31ace commit f3f00fc

File tree

45 files changed

+893
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+893
-78
lines changed

integration/ServiceTestRuleSample/app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
defaultConfig {
77
applicationId "com.example.android.testing.integrationtesting.ServiceTestRuleSample"
88
minSdkVersion 14
9-
targetSdkVersion 26
9+
targetSdkVersion 28
1010
versionCode 1
1111
versionName "1.0"
1212

integration/ServiceTestRuleSample/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ allprojects {
2525
ext {
2626
buildToolsVersion = "28.0.3"
2727
androidxLibVersion = "1.0.0"
28-
coreVersion = "1.2.1-alpha02"
29-
extJUnitVersion = "1.1.2-alpha02"
30-
runnerVersion = "1.3.0-alpha02"
31-
rulesVersion = "1.3.0-alpha02"
28+
coreVersion = "1.3.0-alpha03"
29+
extJUnitVersion = "1.1.2-alpha03"
30+
runnerVersion = "1.3.0-alpha03"
31+
rulesVersion = "1.3.0-alpha03"
3232
}

runner/AndroidJunitRunnerSample/build.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ ext {
2626
buildToolsVersion = "28.0.3"
2727
androidxLibVersion = "1.0.0"
2828
guavaVersion = "26.0-android"
29-
coreVersion = "1.2.1-alpha02"
30-
extJUnitVersion = "1.1.2-alpha02"
31-
runnerVersion = "1.3.0-alpha02"
32-
rulesVersion = "1.3.0-alpha02"
33-
espressoVersion = "3.3.0-alpha02"
29+
coreVersion = "1.3.0-alpha03"
30+
extJUnitVersion = "1.1.2-alpha03"
31+
runnerVersion = "1.3.0-alpha03"
32+
rulesVersion = "1.3.0-alpha03"
33+
espressoVersion = "3.3.0-alpha03"
3434
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gradle
2+
local.properties
3+
.idea
4+
.DS_Store
5+
build
6+
*.iml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
licenses(["notice"]) # Apache 2.0
2+
3+
load("//:common_defs.bzl", "minSdkVersion", "targetSdkVersion")
4+
load("@rules_jvm_external//:defs.bzl", "artifact")
5+
6+
android_library(
7+
name = "BasicSampleLib",
8+
srcs = glob(["app/src/main/**/*.java"]),
9+
custom_package = "com.example.android.testing.espresso.BasicSample",
10+
manifest = "app/src/main/AndroidManifest.xml",
11+
resource_files = glob(["app/src/main/res/**/*"]),
12+
deps = [
13+
artifact("com.google.guava:guava")
14+
],
15+
)
16+
17+
android_binary(
18+
name = "BasicSample",
19+
custom_package = "com.example.android.testing.espresso.BasicSample",
20+
manifest = "app/src/main/AppManifest.xml",
21+
manifest_values = {
22+
"minSdkVersion": minSdkVersion,
23+
"targetSdkVersion": targetSdkVersion,
24+
},
25+
deps = [":BasicSampleLib"],
26+
)
27+
28+
android_library(
29+
name = "BasicSampleTestLib",
30+
srcs = glob(["app/src/androidTest/**/*.java"]),
31+
custom_package = "com.example.android.testing.espresso.BasicSample.test",
32+
deps = [
33+
":BasicSampleLib",
34+
"//:test_deps",
35+
],
36+
)
37+
38+
android_binary(
39+
name = "BasicSampleTest",
40+
custom_package = "com.example.android.testing.espresso.BasicSample.test",
41+
instruments = ":BasicSample",
42+
manifest = "app/src/androidTest/AndroidManifest.xml",
43+
manifest_values = {
44+
"minSdkVersion": minSdkVersion,
45+
"targetSdkVersion": targetSdkVersion,
46+
},
47+
deps = [":BasicSampleTestLib"],
48+
)
49+
50+
API_LEVELS = [
51+
"19_x86",
52+
"21_x86",
53+
"22_x86",
54+
"23_x86",
55+
]
56+
57+
[android_instrumentation_test(
58+
name = "BasicSampleInstrumentationTest_%s" % API_LEVEL,
59+
target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_%s_qemu2" % API_LEVEL,
60+
test_app = ":BasicSampleTest",
61+
) for API_LEVEL in API_LEVELS]
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Basic sample for Espresso
2+
3+
*If you are new to Espresso, try this sample first.*
4+
5+
This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio 3.4 is recommended.
6+
7+
1. Download the project code, preferably using `git clone`.
8+
1. In Android Studio, select *File* | *Open...* and point to the `./build.gradle` file.
9+
1. Check out the relevant code:
10+
* The application under test is located in `src/main/java`
11+
* Instrumentation Tests are in `src/androidTest/java`
12+
* Local Tests are in `src/test/java`
13+
1. Create and run the Instrumented test configuration
14+
* Open *Run* menu | *Edit Configurations*
15+
* Add a new *Android Instrumented Tests* configuration
16+
* Choose the `app` module
17+
* Connect a device or start an emulator
18+
* Turn animations off.
19+
(On your device, under Settings->Developer options disable the following 3 settings: "Window animation scale", "Transition animation scale" and "Animator duration scale")
20+
* Run the newly created configuration
21+
* The application will be started on the device/emulator and a series of actions will be performed automatically.
22+
1. Create and run the local Test configuration
23+
* Open Run menu | Edit Configurations
24+
* Add a new *Android JUnit * configuration
25+
* Set `Use classpath of module` to `app`
26+
* Set `Class` to `ChangeTextBehaviorLocalTest`
27+
* Run the configuration
28+
* The test will run on local host
29+
30+
If you are using Android Studio, the *Run* window will show the test results.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion rootProject.buildToolsVersion
6+
defaultConfig {
7+
applicationId "com.example.android.testing.espresso.AccessibilitySample"
8+
minSdkVersion 14
9+
targetSdkVersion 29
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
}
15+
lintOptions {
16+
abortOnError false
17+
}
18+
productFlavors {
19+
}
20+
testOptions {
21+
unitTests {
22+
includeAndroidResources = true
23+
}
24+
}
25+
}
26+
27+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
28+
kotlinOptions {
29+
jvmTarget = "1.8"
30+
}
31+
}
32+
33+
dependencies {
34+
// App dependencies
35+
implementation 'androidx.annotation:annotation:' + rootProject.androidxLibVersion;
36+
implementation 'com.google.guava:guava:26.0-android'
37+
// accessibility breaks without this on classpath
38+
implementation 'com.android.support:viewpager:28.0.0-alpha1'
39+
40+
// Testing-only dependencies
41+
androidTestImplementation 'androidx.test:core:' + rootProject.coreVersion
42+
androidTestImplementation 'androidx.test.ext:junit:' + rootProject.extJUnitVersion
43+
androidTestImplementation 'androidx.test:runner:' + rootProject.runnerVersion
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:' + rootProject.espressoVersion
45+
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:' + rootProject.espressoVersion
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2018 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
package="com.example.android.testing.espresso.AccessibilitySample.test"
20+
android:versionCode="1"
21+
android:versionName="1.0">
22+
23+
<instrumentation android:targetPackage="com.example.android.testing.espresso.AccessibilitySample"
24+
android:name="androidx.test.runner.AndroidJUnitRunner"/>
25+
26+
<application tools:replace="label" android:label="AccessibilitySampleTest" />
27+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2015, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.testing.espresso.AccessibilitySample;
18+
19+
import static androidx.test.espresso.Espresso.onView;
20+
import static androidx.test.espresso.action.ViewActions.click;
21+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
22+
23+
import androidx.test.core.app.ActivityScenario;
24+
import androidx.test.espresso.accessibility.AccessibilityChecks;
25+
import androidx.test.ext.junit.runners.AndroidJUnit4;
26+
import androidx.test.filters.LargeTest;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
30+
31+
/**
32+
* Basic tests showcasing espresso AccessibilityChecks.
33+
*/
34+
@RunWith(AndroidJUnit4.class)
35+
@LargeTest
36+
public class AccessibilityChecksTest {
37+
38+
@Test
39+
public void accessibilityChecks() {
40+
AccessibilityChecks.enable();
41+
try (ActivityScenario scenario = ActivityScenario.launch(MainActivity.class)) {
42+
onView(withId(R.id.openBrowserButton)).perform(click());
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2015 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.example.android.testing.espresso.AccessibilitySample" >
20+
21+
<application
22+
android:icon="@drawable/ic_launcher"
23+
android:label="@string/app_name"
24+
android:theme="@style/AppTheme" >
25+
<activity
26+
android:name="com.example.android.testing.espresso.AccessibilitySample.MainActivity"
27+
android:label="@string/app_name" >
28+
<intent-filter>
29+
<action android:name="android.intent.action.MAIN" />
30+
<category android:name="android.intent.category.LAUNCHER" />
31+
</intent-filter>
32+
</activity>
33+
</application>
34+
35+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2018 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.example.android.testing.espresso.AccessibilitySample" >
20+
21+
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" />
22+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2015, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.testing.espresso.AccessibilitySample;
18+
19+
import android.app.Activity;
20+
import android.content.Intent;
21+
import android.net.Uri;
22+
import android.os.Bundle;
23+
import android.view.View;
24+
import android.widget.EditText;
25+
import android.widget.TextView;
26+
27+
/**
28+
* An {@link Activity} that gets a text string from the user and displays it back when the user
29+
* clicks on one of the two buttons. The first one shows it in the same activity and the second
30+
* one opens another activity and displays the message.
31+
*/
32+
public class MainActivity extends Activity implements View.OnClickListener {
33+
34+
@Override
35+
protected void onCreate(Bundle savedInstanceState) {
36+
super.onCreate(savedInstanceState);
37+
setContentView(R.layout.activity_main);
38+
39+
}
40+
41+
@Override
42+
public void onClick(View view) {
43+
// fire a intent
44+
Intent intent = new Intent(Intent.ACTION_VIEW);
45+
intent.setData(Uri.parse("http://developer.android.com"));
46+
startActivity(intent);
47+
}
48+
}
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)