Skip to content

Commit

Permalink
Restructure emulator tests for better bazel support.
Browse files Browse the repository at this point in the history
Bazel wants a structure where the application used for testing and the tests themselves are in separate packages (which gradle is less picky about). Android has a gradle plugin for this setup (com.android.test), although it unfortunately has seemingly worse Android Studio support at this point. In any case, this change splits the code up a bit more, into 3 parts:

- lib: the files we actually distribute as a library to end users
- testing: the test application and its custom component subclasses that are tested by the emulator tests
- tests: the actual emulator test code

The structure is a tad strange for typical gradle projects (testing in particular, which has a build.gradle file for each individual Java package, at the same level as the actual source files), but it better matches the conventions of bazel while also avoiding the need for a ton of parallel directory structures at the top level.

Known issues as of this commit:
- Android Studio doesn't think the Java files in testing/ have the right package. I tried to fix this by bumping their java srcDir up to the java/ root and changing the includes, but Android studio seems unable to properly figure that out and instead acted like the Java files didn't exist at all, so I reverted that. We can possibly modify the iml files that get generated, but I'll save this for a follow-up commit since this is already very large.

- Android Studio seems unable to run emulator tests properly (but they work from the command-line). I don't quite know why they fail, but seems like lacking support for the com.android.test plugin. Hopefully this is something we can work around for find a fix for in the near future.

PiperOrigin-RevId: 146940681
  • Loading branch information
travisc committed Feb 8, 2017
1 parent a562f06 commit 69a7021
Show file tree
Hide file tree
Showing 161 changed files with 901 additions and 668 deletions.
25 changes: 18 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ subprojects {
project.plugins.whenPluginAdded { plugin ->
def isAndroidLibrary = "com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)
def isAndroidApp = "com.android.build.gradle.AppPlugin".equals(plugin.class.name)
def isJavaLibrary = "org.gradle.api.plugins.JavaPlugin".equals(plugin.class.name)
def isAndroidTest = "com.android.build.gradle.TestPlugin".equals(plugin.class.name)

if (isAndroidLibrary || isAndroidApp) {
if (isAndroidLibrary || isAndroidApp || isAndroidTest) {
// Enable code coverage for debug builds only if we are not running inside the IDE,
// since enabling coverage reports breaks the method parameter resolution in the IDE
// debugger.
Expand All @@ -63,14 +63,25 @@ subprojects {
// Enforce NewApi lint check as fatal.
project.android.lintOptions.check 'NewApi'
project.android.lintOptions.fatal 'NewApi'
project.parent.lint.dependsOn project.lint

// Disable pre-dexing when gradle called with -PdisablePreDex;
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}

if (isAndroidLibrary || isJavaLibrary) {
// TODO: setup maven release building?
rootProject.lint.dependsOn project.lint

project.android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig.minSdkVersion rootProject.ext.minSdkVersion
defaultConfig.targetSdkVersion rootProject.ext.targetSdkVersion
// This disables the builds tools automatic vector -> PNG generation
defaultConfig.generatedDensities = []

compileOptions.sourceCompatibility JavaVersion.VERSION_1_7
compileOptions.targetCompatibility JavaVersion.VERSION_1_7

aaptOptions.additionalParameters "--no-version-vectors"
}
}
}
}
38 changes: 0 additions & 38 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,13 @@ dependencies {
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:transition:25.1.0'

androidTestCompile ("com.android.support.test:runner:${project.rootProject.ext.testRunnerVersion}") {
exclude module: 'support-annotations'
}
androidTestCompile ("com.android.support.test.espresso:espresso-core:${project.rootProject.ext.espressoVersion}") {
exclude module: 'support-annotations'
}
androidTestCompile ("com.android.support.test.espresso:espresso-contrib:${project.rootProject.ext.espressoVersion}") {
exclude group: 'com.android.support'
}
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

testCompile ("com.android.support.test:runner:${project.rootProject.ext.testRunnerVersion}") {
exclude module: 'support-annotations'
}
testCompile 'junit:junit:4.12'
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// This disables the builds tools automatic vector -> PNG generation
generatedDensities = []
}

sourceSets {
main.manifest.srcFile 'AndroidManifest.xml'
main.java.srcDirs = [
Expand All @@ -58,26 +34,12 @@ android {
main.assets.srcDir 'assets'
main.resources.srcDir 'src'

androidTest.setRoot('tests')
androidTest.java.srcDir 'tests/src'
androidTest.res.srcDir 'tests/res'
androidTest.manifest.srcFile 'tests/AndroidManifest.xml'

test.java.srcDir 'jvmtests/javatests'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes.all {
consumerProguardFiles 'proguard-rules.pro'
}

aaptOptions {
additionalParameters "--no-version-vectors"
}
}

android.libraryVariants.all { variant ->
Expand Down
97 changes: 0 additions & 97 deletions lib/tests/AndroidManifest.xml

This file was deleted.

39 changes: 0 additions & 39 deletions lib/tests/res/values/styles.xml

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include ':lib'
include ':tests'
include ':testing:java:android:support:design:testapp'
include ':testing:java:android:support:design:testapp:custom'
File renamed without changes.
5 changes: 5 additions & 0 deletions testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# testing

This directory contains the sources for test fixtures, activities, and
applications used in emulator tests (but not actual test code, which lives under
[../tests/](../tests)).
89 changes: 89 additions & 0 deletions testing/java/android/support/design/testapp/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="android.support.design.testapp">

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="25"
tools:overrideLibrary="android.support.test, android.app, android.support.test.rule, android.support.test.espresso, android.support.test.espresso.idling"/>

<application
android:supportsRtl="true"
android:theme="@style/Theme.Design">

<activity android:name="android.support.v7.app.AppCompatActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".BottomNavigationViewActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".BottomSheetBehaviorActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".BottomSheetBehaviorWithInsetsActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".BottomSheetDialogActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".CoordinatorLayoutActivity"/>

<activity
android:theme="@style/Theme.TranslucentStatus"
android:name=".DynamicCoordinatorLayoutActivity"/>

<activity
android:name=".FloatingActionButtonActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".NavigationViewActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".SnackbarActivity"/>

<activity
android:theme="@style/Theme.TranslucentNavBar"
android:name=".SnackbarWithTranslucentNavBarActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".SnackbarWithFabActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".TabLayoutPoolingActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".TabLayoutWithViewPagerActivity"/>

<activity
android:theme="@style/Theme.AppCompat.NoActionBar"
android:name=".TextInputLayoutActivity"/>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package android.support.design.widget;
package android.support.design.testapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand Down
Loading

0 comments on commit 69a7021

Please sign in to comment.