Make unit tests work with Gradle

Had to split the test app from the tests, since that's how gradle forces
you to do it.
This commit is contained in:
Andrew Grieve 2015-01-20 13:58:58 -05:00
parent e788e8fa0f
commit 0e19f88a04
20 changed files with 131 additions and 39 deletions

34
.gitignore vendored
View File

@ -2,28 +2,28 @@
default.properties
gen
assets/www/cordova.js
framework/assets/www/.tmp*
local.properties
framework/lib
proguard.cfg
proguard.cfg
proguard-project.txt
framework/bin
framework/test/org/apache/cordova/*.class
framework/assets/www/.DS_Store
framework/assets/www/cordova-*.js
framework/assets/www/phonegap-*.js
framework/libs
framework/javadoc-public
framework/javadoc-private
test/libs
/framework/lib
/framework/build
/framework/bin
/framework/assets/www/.DS_Store
/framework/assets/www/cordova-*.js
/framework/assets/www/phonegap-*.js
/framework/libs
/framework/javadoc-public
/framework/javadoc-private
/test/libs
example
./test
test/bin
test/assets/www/.tmp*
test/assets/www/cordova.js
test/cordova/plugins/org.apache.cordova.device/www/device.js
test/cordova/plugins/org.apache.cordova.device/src/android/Device.java
/test/bin
/test/assets/www/.tmp*
/test/assets/www/cordova.js
/test/gradle
/test/gradlew
/test/build
.gradle
tmp/**
.metadata
tmp/**/*

View File

@ -18,34 +18,47 @@
# under the License.
#
-->
# Android Native Tests #
# Android Native Tests
These tests are designed to verify Android native features and other Android specific features.
They currently are in disrepair, and don't pass / work on KitKat+ :(.
## Initial Setup ##
## Initial Setup
There really isn't any manual setup to do. The ant script takes care of that.
You don't even need to compile cordova-x.y.z.jar or copy it, because
project.properties has a library reference to ../framework. However, Robotium
has to be installed for the onScrollChanged tests to work correctly. It can be
### Setting env vars
Run:
../bin/check_reqs
Use the output to set your `ANDROID_HOME` and `JAVA_HOME` environment variables.
### Adding `gradlew`
Copy it from a freshly created project:
../bin/create foo
(cd foo && cordova/build --gradle; cp -r gradlew gradle ..)
rm -r foo
### Robotium
Robotium has to be installed for the onScrollChanged tests to work correctly. It can be
found at https://code.google.com/p/robotium/ and the jar should be put in the
'libs' directory'.
'androidTests/libs' directory'.
To run manually from command line:
## Running
0. Build by entering `ant debug install`
0. Run tests by clicking on "CordovaNativeTests" app icon on the device
To run manual tests:
To run from Eclipse:
./gradlew installDebug
0. Import Android project into Eclipse
0. Ensure Project properties "Java Build Path" includes the lib/cordova-x.y.z.jar
0. Create run configuration if not already created
0. Run As -> Android JUnit Test
To run unit tests:
## Automatic Runs ##
./gradlew connectedAndroidTest
Once you have installed the test, you can launch and run the tests
automatically with the below command:
## Android Studio
adb shell am instrument -w org.apache.cordova.test/android.test.InstrumentationTestRunner
1. Use "Non-Android Studio Project" to import the `test` directory.
2. Right click on the `junit` package in the left-side nav
3. Select "Debug"`->`_The one with the Android icon_

75
test/build.gradle Normal file
View File

@ -0,0 +1,75 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
*/
// GENERATED FILE! DO NOT EDIT!
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
}
}
ext {
apply from: '../framework/cordova.gradle'
cdvCompileSdkVersion = privateHelpers.getProjectTarget()
cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest {
java.srcDirs = ['androidTest/src']
resources.srcDirs = ['androidTest/src']
res.srcDirs = []
assets.srcDirs = []
}
}
defaultConfig {
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
compileSdkVersion cdvCompileSdkVersion
buildToolsVersion cdvBuildToolsVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
debugCompile project(path: ":CordovaLib", configuration: "debug")
releaseCompile project(path: ":CordovaLib", configuration: "release")
androidTestCompile fileTree(dir: 'androidTest/libs', include: '*.jar')
}

View File

@ -8,5 +8,5 @@
# project structure.
# Project target.
target=android-19
target=android-21
android.library.reference.1=../framework

4
test/settings.gradle Normal file
View File

@ -0,0 +1,4 @@
include ":"
include ":CordovaLib"
project(':CordovaLib').projectDir = new File('../framework')