diff options
author | Alexander Lucas <alexlucas@google.com> | 2013-09-13 13:54:41 -0700 |
---|---|---|
committer | Alexander Lucas <alexlucas@google.com> | 2013-09-13 13:54:41 -0700 |
commit | 49024b64c5d3362eb4aa496afa913c7280488c58 (patch) | |
tree | b8a99936f98d6f11707938a28947effc8fd76f4d | |
parent | ecdaad3d42523859ad93b0d32313c18d99c4629b (diff) | |
download | build-49024b64c5d3362eb4aa496afa913c7280488c58.tar.gz |
Added tests to base template, fixed some default values.
Change-Id: Ib131f345244f9397be3e887a8a489f7b3d73c9a3
4 files changed, 115 insertions, 7 deletions
diff --git a/templates/SingleView/_MODULE_/src/template/res/values/strings.xml.ftl b/templates/SingleView/_MODULE_/src/template/res/values/strings.xml.ftl index d23f0463..b7af2570 100755 --- a/templates/SingleView/_MODULE_/src/template/res/values/strings.xml.ftl +++ b/templates/SingleView/_MODULE_/src/template/res/values/strings.xml.ftl @@ -15,5 +15,9 @@ limitations under the License. --> <resources> - <string name="sample_action">${sample.strings.sample_action!"Try it out!"}</string> + <#if (sample.strings.sample_action)?is_string> + <string name="sample_action">${sample.strings.sample_action}</string> + <#else> + <string name="sample_action">TODO: Add strings/!sample_action!</string> + </#if> </resources> diff --git a/templates/base/_MODULE_/build.gradle.ftl b/templates/base/_MODULE_/build.gradle.ftl index 7cb6fd12..6d9b5f2f 100644 --- a/templates/base/_MODULE_/build.gradle.ftl +++ b/templates/base/_MODULE_/build.gradle.ftl @@ -48,10 +48,13 @@ List<String> dirs = [ android { <#-- Note that target SDK is hardcoded in this template. We expect all samples to always use the most current SDK as their target. --> - compileSdkVersion ${sample.compileSdkVersion!18} +<#if (sample.compileSdkVersion)?is_number || (sample.compileSdkVersion)?is_string> + compileSdkVersion ${sample.compileSdkVersion} +<#else> + compileSdkVersion 18 +</#if> buildToolsVersion "18.0.1" - sourceSets { main { dirs.each { dir -> @@ -61,11 +64,9 @@ android { </#noparse> } } + instrumentTest.setRoot('tests') + instrumentTest.java.srcDirs = ['tests/src'] } - - instrumentTest.setRoot('tests') - instrumentTest.java.srcDirs = ['tests/src'] - } task preflight (dependsOn: parent.preflight) { diff --git a/templates/create/_MODULE_/tests/AndroidManifest.xml b/templates/create/_MODULE_/tests/AndroidManifest.xml new file mode 100644 index 00000000..87b785fb --- /dev/null +++ b/templates/create/_MODULE_/tests/AndroidManifest.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2013 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 name must be unique so suffix with "tests" so package loader doesn't ignore us --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="${sample.package}.tests" + android:versionCode="1" + android:versionName="1.0"> + + <uses-sdk + android:minSdkVersion="18" + android:targetSdkVersion="19" /> + + <!-- We add an application tag here just so that we can indicate that + this package needs to link against the android.test library, + which is needed when building test cases. --> + <application> + <uses-library android:name="android.test.runner" /> + </application> + + <!-- + Specifies the instrumentation test runner used to run the tests. + --> + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="${sample.package}" + android:label="Tests for ${sample.package}" /> + +</manifest>
\ No newline at end of file diff --git a/templates/create/_MODULE_/tests/src/_PACKAGE_/tests/SampleTests.java.ftl b/templates/create/_MODULE_/tests/src/_PACKAGE_/tests/SampleTests.java.ftl new file mode 100644 index 00000000..87ee8809 --- /dev/null +++ b/templates/create/_MODULE_/tests/src/_PACKAGE_/tests/SampleTests.java.ftl @@ -0,0 +1,61 @@ +/* +* Copyright (C) 2013 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 ${sample.package}.tests; + +import ${sample.package}.*; + +import android.test.ActivityInstrumentationTestCase2; + +/** +* Tests for ${sample.name} sample. +*/ +public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> { + + private MainActivity mTestActivity; + private ${sample.name?cap_first}Fragment mTestFragment; + + public SampleTests() { + super(MainActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // Starts the activity under test using the default Intent with: + // action = {@link Intent#ACTION_MAIN} + // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK} + // All other fields are null or empty. + mTestActivity = getActivity(); + mTestFragment = (${sample.name?cap_first}Fragment) + mTestActivity.getSupportFragmentManager().getFragments().get(1); + } + + /** + * Test if the test fixture has been set up correctly. + */ + public void testPreconditions() { + //Try to add a message to add context to your assertions. These messages will be shown if + //a tests fails and make it easy to understand why a test failed + assertNotNull("mTestActivity is null", mTestActivity); + assertNotNull("mTestFragment is null", mTestFragment); + } + + /** + * Add more tests below. + */ + +}
\ No newline at end of file |