aboutsummaryrefslogtreecommitdiff
path: root/gradle/src/device-test
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2013-02-07 14:00:13 -0800
committerXavier Ducrohet <xav@android.com>2013-02-07 14:02:55 -0800
commit358e8e001966a7eee1f4c0e2ae73b0b52b93f505 (patch)
tree92227204396dc4edf427aa6d9ed88fa08e1c7ee3 /gradle/src/device-test
parent56b5e776c3244d71d7d171009980334e716ecf64 (diff)
downloadbuild-358e8e001966a7eee1f4c0e2ae73b0b52b93f505.tar.gz
Automate testing build output on devices.
This is to test the plugin itself, not a feature of the plugin. 'gradlew deviceTest' is similar to 'gradlew buildTest' in that it requires an SDK through ANDROID_HOME, and then builds a set of projects. It differs in that it then pushed the project (and its test project) to a connected device and runs the test there. Note: This is even longer running that buildTest, and since it requires a device, it is not a dependence on check. This must be run separately. Change-Id: I9d211ef22a680a4fba62314e943de3fdd54e4eee
Diffstat (limited to 'gradle/src/device-test')
-rw-r--r--gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.groovy92
-rw-r--r--gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java79
2 files changed, 79 insertions, 92 deletions
diff --git a/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.groovy b/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.groovy
deleted file mode 100644
index 73a592a..0000000
--- a/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.groovy
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-package com.android.build.gradle
-
-import com.android.build.gradle.internal.test.BaseTest
-
-/**
- * Device tests.
- *
- * This build relies on the {@link BuildTest} to have been run, so that all that there
- * is left to do is deploy the tested and test apps to the device and run the tests (and gather
- * the result).
- *
- * The dependency on the build tests is ensured by the gradle tasks definition.
- *
- * This does not test every projects under tests, instead it's a selection that actually has
- * tests.
- *
- */
-public class DeviceTest extends BaseTest {
-
- private File testDir
- private File sdkDir
-
- @Override
- protected void setUp() throws Exception {
- testDir = getTestDir()
- sdkDir = getSdkDir()
- }
-
- void testApi() {
- runTestsOn("api")
- }
-
- void testAppLibTest() {
- runTestsOn("applibtest")
- }
-
- void testBasic() {
- runTestsOn("basic")
- }
-
- void testFlavored() {
- runTestsOn("flavored")
- }
-
- void testFlavorLib() {
- runTestsOn("flavorlib")
- }
-
- void testFlavors() {
- runTestsOn("flavors")
- }
-
- void testLibsTest() {
- runTestsOn("libsTest")
- }
-
- void testMigrated() {
- runTestsOn("migrated")
- }
-
- void testMultiRes() {
- runTestsOn("multires")
- }
-
- void testOverlay1() {
- runTestsOn("overlay1")
- }
-
- void testOverlay2() {
- runTestsOn("overlay2")
- }
-
- private File runTestsOn(String name) {
- return runGradleTasks(name, "check")
- }
-} \ No newline at end of file
diff --git a/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java b/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java
new file mode 100644
index 0000000..778327f
--- /dev/null
+++ b/gradle/src/device-test/groovy/com/android/build/gradle/DeviceTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.build.gradle;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Device tests.
+ *
+ * This build relies on the {@link BuildTest} to have been run, so that all that there
+ * is left to do is deploy the tested and test apps to the device and run the tests (and gather
+ * the result).
+ *
+ * The dependency on the build tests is ensured by the gradle tasks definition.
+ *
+ * This does not test every projects under tests, instead it's a selection that actually has
+ * tests.
+ *
+ */
+public class DeviceTest extends BuildTest {
+
+ private String projectName;
+ private String gradleVersion;
+
+ private static final String[] sBuiltProjects = new String[] {
+ "api", "applibtest", "basic", "flavored", "flavorlib",
+ "flavors", "libsTest", "migrated", "multires", "overlay1", "overlay2",
+ };
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.setName("DeviceTest");
+
+ for (String gradleVersion : BasePlugin.GRADLE_SUPPORTED_VERSIONS) {
+ // first the project we build on all available versions of Gradle
+ for (String projectName : sBuiltProjects) {
+ String testName = "check_" + projectName + "_" + gradleVersion;
+
+ DeviceTest test = (DeviceTest) TestSuite.createTest(DeviceTest.class, testName);
+ test.setProjectInfo(projectName, gradleVersion);
+ suite.addTest(test);
+ }
+ }
+
+ return suite;
+ }
+
+ private void setProjectInfo(String projectName, String gradleVersion) {
+ this.projectName = projectName;
+ this.gradleVersion = gradleVersion;
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ try {
+ runTasksOnProject(projectName, gradleVersion, "check");
+ } finally {
+ // because runTasksOnProject will throw an exception if the gradle side fails, do this
+ // in the finally block.
+
+ // TODO: Get the test output and copy it in here.
+ }
+ }
+} \ No newline at end of file