Bug 1171566 - Part 1: Configure Gradle and Spoon. rs=mcomella

There are few things happening here:

* A purely mechanical move of test sources into org.mozilla.test.browser.junit3.
  This is only to make it easy to specify the suite in Spoon.  (But it has the
  advantage of making it possible to move files around in IntelliJ, since the
  symlink points to src instead of org/mozilla/gecko.)

* Specifying the suite (package name) ended up requiring changes to the
  spoon-gradle-plugin anyway.  Hence, I've included this custom
  spoon-gradle-plugin version locally, while I work to upstream the changes.

* Some Gradle trickery to make |mach gradle runBrowserTests| execute Spoon with
  the correct package name.
This commit is contained in:
Nick Alexander 2015-06-04 12:09:23 -07:00
parent dab3487099
commit 7ebc0ca509
24 changed files with 163 additions and 51 deletions

View File

@ -73,3 +73,36 @@ android.applicationVariants.all { variant ->
def generateAssetsTask = tasks.findByName("generate${name.capitalize()}Assets")
generateAssetsTask.dependsOn buildOmnijarTask
}
apply plugin: 'spoon'
spoon {
// For now, let's be verbose.
debug = true
// It's not helpful to pass when we don't have a device connected.
failIfNoDeviceConnected = true
def spoonPackageName
if (gradle.startParameter.taskNames.contains('runBrowserTests')) {
spoonPackageName = 'org.mozilla.tests.browser.junit3'
}
if (project.hasProperty('spoonPackageName')) {
// Command line overrides everything.
spoonPackageName = project.spoonPackageName
}
if (spoonPackageName) {
instrumentationArgs = ['-e', "package=${spoonPackageName}".toString()]
}
}
// See discussion at https://github.com/stanfy/spoon-gradle-plugin/issues/9.
afterEvaluate {
tasks["spoon${android.testBuildType.capitalize()}AndroidTest"].outputs.upToDateWhen { false }
// This is an awkward way to define different sets of instrumentation tests.
// The task name itself is fished at runtime and the package name configured
// in the spoon configuration.
task runBrowserTests {
dependsOn tasks["spoonDebugAndroidTest"]
}
}

View File

@ -16,6 +16,17 @@ buildDir "${topobjdir}/mobile/android/gradle/build"
buildscript {
repositories {
jcenter()
// For spoon-gradle-plugin SNAPSHOT release. This needs to go before
// the snapshots repository, otherwise we find a remote 1.0.3-SNAPSHOT
// that doesn't include nalexander's local changes.
maven {
url "file://${topsrcdir}/mobile/android/gradle/m2repo"
}
// For spoon SNAPSHOT releases.
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
@ -23,6 +34,10 @@ buildscript {
// 1.0.0. There are major issues with the combination of 0.14.4, Gradle
// 2.2.1, and IntelliJ 14.0.2: see Bug 1120032.
classpath 'com.android.tools.build:gradle:1.0.0'
classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.3-SNAPSHOT') {
// Without these, we get errors linting.
exclude module: 'guava'
}
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.stanfy.spoon</groupId>
<artifactId>spoon-gradle-plugin</artifactId>
<version>1.0.3-SNAPSHOT</version>
<versioning>
<snapshot>
<localCopy>true</localCopy>
</snapshot>
<lastUpdated>20150603215211</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stanfy.spoon</groupId>
<artifactId>spoon-gradle-plugin</artifactId>
<version>1.0.3-SNAPSHOT</version>
<name>Spoon Gradle Plugin</name>
<description>Gradle plugin for Spoon</description>
<url>https://github.com/stanfy/spoon-gradle-plugin</url>
<inceptionYear>2013</inceptionYear>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>rmazur</id>
<name>Roman Mazur</name>
<email>rmazur@stanfy.com.ua</email>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:stanfy/spoon-gradle-plugin.git</connection>
<developerConnection>scm:git:git@github.com:stanfy/spoon-gradle-plugin.git</developerConnection>
<url>https://github.com/stanfy/spoon-gradle-plugin</url>
</scm>
<dependencies>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.spoon</groupId>
<artifactId>spoon-runner</artifactId>
<version>1.1.10-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>1.1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.stanfy.spoon</groupId>
<artifactId>spoon-gradle-plugin</artifactId>
<version>1.0.3-SNAPSHOT</version>
<versioning>
<versions>
<version>1.0.3-SNAPSHOT</version>
</versions>
<lastUpdated>20150603215211</lastUpdated>
</versioning>
</metadata>

View File

@ -125,7 +125,7 @@ class MachCommands(MachCommandBase):
srcdir('app/src/robocop_harness/org/mozilla/gecko', 'build/mobile/robocop')
srcdir('app/src/robocop/org/mozilla/gecko/tests', 'mobile/android/tests/browser/robocop')
srcdir('app/src/background/org/mozilla/gecko', 'mobile/android/tests/background/junit3/src')
srcdir('app/src/browser/org/mozilla/gecko', 'mobile/android/tests/browser/junit3/src')
srcdir('app/src/browser', 'mobile/android/tests/browser/junit3/src')
# Test libraries.
srcdir('app/libs', 'build/mobile/robocop')

View File

@ -1,10 +1,10 @@
[DEFAULT]
subsuite = browser
[src/TestDistribution.java]
[src/TestGeckoSharedPrefs.java]
[src/TestImageDownloader.java]
[src/TestJarReader.java]
[src/TestRawResource.java]
[src/TestSuggestedSites.java]
[src/TestTopSitesCursorWrapper.java]
[src/org/mozilla/tests/browser/junit3/TestDistribution.java]
[src/org/mozilla/tests/browser/junit3/TestGeckoSharedPrefs.java]
[src/org/mozilla/tests/browser/junit3/TestImageDownloader.java]
[src/org/mozilla/tests/browser/junit3/TestJarReader.java]
[src/org/mozilla/tests/browser/junit3/TestRawResource.java]
[src/org/mozilla/tests/browser/junit3/TestSuggestedSites.java]
[src/org/mozilla/tests/browser/junit3/TestTopSitesCursorWrapper.java]

View File

@ -8,37 +8,21 @@ DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME']
jar = add_java_jar('browser-junit3')
jar.sources += [
'src/BrowserTestCase.java',
'src/harness/BrowserInstrumentationTestRunner.java',
'src/harness/BrowserTestListener.java',
'src/TestDistribution.java',
'src/TestGeckoBackgroundThread.java',
'src/TestGeckoMenu.java',
'src/TestGeckoProfilesProvider.java',
'src/TestGeckoSharedPrefs.java',
'src/TestImageDownloader.java',
'src/TestJarReader.java',
'src/TestRawResource.java',
'src/TestSuggestedSites.java',
'src/TestTopSitesCursorWrapper.java',
'src/org/mozilla/tests/browser/junit3/BrowserTestCase.java',
'src/org/mozilla/tests/browser/junit3/harness/BrowserInstrumentationTestRunner.java',
'src/org/mozilla/tests/browser/junit3/harness/BrowserTestListener.java',
'src/org/mozilla/tests/browser/junit3/TestDistribution.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoBackgroundThread.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoMenu.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoProfilesProvider.java',
'src/org/mozilla/tests/browser/junit3/TestGeckoSharedPrefs.java',
'src/org/mozilla/tests/browser/junit3/TestImageDownloader.java',
'src/org/mozilla/tests/browser/junit3/TestJarReader.java',
'src/org/mozilla/tests/browser/junit3/TestRawResource.java',
'src/org/mozilla/tests/browser/junit3/TestSuggestedSites.java',
'src/org/mozilla/tests/browser/junit3/TestTopSitesCursorWrapper.java',
]
jar.generated_sources = [] # None yet -- try to keep it this way.
jar.javac_flags += ['-Xlint:all,-unchecked']
# Android Eclipse project.
main = add_android_eclipse_project('BrowserInstrumentationTests', OBJDIR + '/AndroidManifest.xml')
# The package name doesn't really matter, but it looks nicest if the
# generated classes (org.mozilla.gecko.browser.tests.{BuildConfig,R})
# are in the same hierarchy as the rest of the source files.
main.package_name = 'org.mozilla.gecko.browser.tests'
main.res = 'res'
main.recursive_make_targets += [
OBJDIR + '/AndroidManifest.xml',
]
main.recursive_make_targets += [OBJDIR + '/generated/' + f for f in jar.generated_sources]
main.referenced_projects += ['Fennec']
main.add_classpathentry('src', SRCDIR + '/src',
dstdir='src/org/mozilla/gecko')
jar.javac_flags += ['-Xlint:all']
ANDROID_INSTRUMENTATION_MANIFESTS += ['instrumentation.ini']

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import org.mozilla.gecko.AppConstants;

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import org.mozilla.gecko.distribution.ReferrerDescriptor;

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import org.mozilla.gecko.util.ThreadUtils;

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.menu.GeckoMenu;

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import java.io.File;
import java.util.HashMap;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import java.util.Arrays;
import java.util.Collections;
@ -9,6 +9,8 @@ import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.GeckoSharedPrefs.Flags;
import android.content.Context;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import android.content.Context;
import android.content.res.Resources;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import java.io.InputStream;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import java.io.ByteArrayInputStream;
import java.io.IOException;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -19,6 +19,9 @@ import java.util.Set;
import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.gecko.R;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Locales;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko;
package org.mozilla.tests.browser.junit3;
import android.database.Cursor;
import android.database.MatrixCursor;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.harness;
package org.mozilla.tests.browser.junit3.harness;
import android.os.Bundle;
import android.test.AndroidTestRunner;

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.gecko.harness;
package org.mozilla.tests.browser.junit3.harness;
import junit.framework.AssertionFailedError;
import junit.framework.Test;