Merge branch 'latest-android-testing-support' into 'master'

use latest android testing support setup

With 2.0 of Android Studio and gradle pluging coming out shortly, I wanted to start trying to use the improved testing setup.  So this is a place to track that stuff until it stabilizes.

See merge request !252
This commit is contained in:
Daniel Martí 2016-05-10 13:31:31 +00:00
commit ac151716c9
4 changed files with 69 additions and 27 deletions

View File

@ -8,6 +8,8 @@ cache:
variables:
AVD_SDK: "17"
SKIN: "QVGA"
# switch glibc to a memory conserving mode
MALLOC_ARENA_MAX: "2"
gradle:
script:
@ -17,9 +19,9 @@ gradle:
# always report on lint errors to the build log
- sed -i -e 's,textReport .*,textReport true,' app/build.gradle
# 'build' means assemble and check
- ./gradlew build || {
- ./gradlew build -PdisablePreDex || {
for log in app/build/reports/*ests/*/*ml; do
echo "read $log here:"
echo "read $log here:";
cat "$log" | curl --silent -F 'clbin=<-' https://clbin.com;
done;
exit 1;
@ -38,9 +40,9 @@ gradle:
--target android-$AVD_SDK
- emulator64-arm -avd fcl-test -no-skin -no-audio -no-window &
- ./tools/wait-for-emulator
- adb shell input keyevent 82
- adb shell input keyevent 82 &
- export EXITVALUE=0
- ADB_INSTALL_TIMEOUT=8 ./gradlew connectedCheck || {
- ADB_INSTALL_TIMEOUT=8 ./gradlew connectedCheck -PdisablePreDex || {
adb -e logcat -d '*:E';
echo "get the full logcat here:";
adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com;
@ -52,17 +54,19 @@ gradle:
cat "$log" | curl --silent -F 'clbin=<-' https://clbin.com;
done
- sed -n 's/.*"ctr2">\([0-9]*\)%<.*/Coverage - \1.0% covered\n/p' app/build/reports/coverage/debug/index.html
# this file changes every time but should not be cached
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
- exit $EXITVALUE
pmd:
script:
- export GRADLE_USER_HOME=$PWD/.gradle
- ./gradlew pmd
- ./gradlew pmd -PdisablePreDex
checkstyle:
script:
- export GRADLE_USER_HOME=$PWD/.gradle
- ./gradlew checkstyle
- ./gradlew checkstyle -PdisablePreDex
tools:
script:

View File

@ -157,8 +157,17 @@ android {
}
testOptions {
// prevent tests from dying on android.util.Log calls
unitTests.returnDefaultValues = true
unitTests {
// prevent tests from dying on android.util.Log calls
returnDefaultValues = true
all {
// All the usual Gradle options.
testLogging {
events "skipped", "failed", "standardOut", "standardError"
showStandardStreams = true
}
}
}
}
lintOptions {

View File

@ -16,13 +16,11 @@ import static org.junit.Assert.fail;
public class HttpDownloaderTest {
String[] urls = {
"https://www.google.com",
"https://en.wikipedia.org/wiki/Index.html",
"https://mirrors.kernel.org/debian/dists/stable/Release",
"https://f-droid.org/archive/de.we.acaldav_5.apk",
"https://f-droid.org/repo/index.jar",
// sites that use SNI for HTTPS
"https://guardianproject.info/fdroid/repo/index.jar",
"https://firstlook.org",
};
private boolean receivedProgress;
@ -42,23 +40,38 @@ public class HttpDownloaderTest {
@Test
public void downloadUninterruptedTestWithProgress() throws IOException, InterruptedException {
for (String urlString : urls) {
receivedProgress = false;
URL url = new URL(urlString);
File destFile = File.createTempFile("dl-", "");
HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
httpDownloader.setListener(new Downloader.DownloaderProgressListener() {
@Override
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
receivedProgress = true;
final CountDownLatch latch = new CountDownLatch(1);
String urlString = "https://f-droid.org/repo/index.jar";
receivedProgress = false;
System.out.println("downloadUninterruptedTestWithProgress: " + urlString);
receivedProgress = false;
URL url = new URL(urlString);
File destFile = File.createTempFile("dl-", "");
final HttpDownloader httpDownloader = new HttpDownloader(url, destFile);
httpDownloader.setListener(new Downloader.DownloaderProgressListener() {
@Override
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
System.out.println("DownloaderProgressListener.sendProgress " + sourceUrl + " " + bytesRead + " / " + totalBytes);
receivedProgress = true;
}
});
new Thread() {
@Override
public void run() {
try {
httpDownloader.download();
latch.countDown();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
fail();
}
});
httpDownloader.download();
assertTrue(destFile.exists());
assertTrue(destFile.canRead());
assertTrue(receivedProgress);
destFile.deleteOnExit();
}
}
}.start();
latch.await(100, TimeUnit.SECONDS); // either 2 progress reports or 100 seconds
assertTrue(destFile.exists());
assertTrue(destFile.canRead());
assertTrue(receivedProgress);
destFile.deleteOnExit();
}
@Test

View File

@ -7,3 +7,19 @@ buildscript {
classpath files('libs/gradle-witness.jar')
}
}
/**
* Improve build server performance by allowing disabling of pre-dexing
* (see http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.)
*/
project.ext.preDexLibs = !project.hasProperty('disablePreDex')
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}