Merge branch 'android-studio-testing-fixes' into 'master'

start porting tests to latest Android Studio/gradle setup

To encourage more people to use and add to the test suite, I've been working on making it work nicely with Android Studio and gradle.  I've also setup the possibility for JUnit tests that run on the host machine, not the emulator.  Those are run with `gradle test`.  I added a JUnit test of `HttpDownloader` too.

See merge request !233
This commit is contained in:
Hans-Christoph Steiner 2016-03-29 11:45:33 +00:00
commit acc2a3154f
532 changed files with 104 additions and 80 deletions

View File

@ -10,14 +10,14 @@ gradle:
- export GRADLE_USER_HOME=$PWD/.gradle
- ./gradlew assemble
# always report on lint errors to the build log
- sed -i -e 's,textReport .*,textReport true,' F-Droid/build.gradle
- sed -i -e 's,textReport .*,textReport true,' app/build.gradle
- ./gradlew check
- echo no | android create avd --force -n fcl-test -t android-10 -b armeabi
- emulator -force-32bit -avd fcl-test -no-skin -no-audio -no-window &
- ./tools/wait-for-emulator
- adb shell input keyevent 82
- ADB_INSTALL_TIMEOUT=8 ./gradlew connectedCheck || { adb logcat -d '*:W'; exit 1; }
- sed -n 's/.*"ctr2">\([0-9]*\)%<.*/Coverage - \1.0% covered\n/p' F-Droid/build/reports/coverage/debug/index.html
- sed -n 's/.*"ctr2">\([0-9]*\)%<.*/Coverage - \1.0% covered\n/p' app/build/reports/coverage/debug/index.html
pmd:
script:
@ -31,6 +31,6 @@ checkstyle:
tools:
script:
- cd F-Droid
- cd app
- ./tools/langs-list-check.py
- ./tools/check-string-format.py

View File

@ -7,7 +7,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := F-Droid
fdroid_root := $(LOCAL_PATH)
fdroid_dir := F-Droid
fdroid_dir := app
fdroid_out := $(PWD)/$(OUT_DIR)/target/common/obj/APPS/$(LOCAL_MODULE)_intermediates
fdroid_build := $(fdroid_root)/$(fdroid_dir)/build
fdroid_apk := build/outputs/apk/F-Droid-release-unsigned.apk
@ -23,4 +23,4 @@ LOCAL_SRC_FILES := $(fdroid_dir)/$(fdroid_apk)
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
include $(BUILD_PREBUILT)

View File

@ -7,8 +7,7 @@ for Android.
## Building with Gradle
cd F-Droid
../gradlew assembleRelease
./gradlew assembleRelease
## Direct download

View File

@ -123,29 +123,6 @@ android {
buildToolsVersion '23.0.2'
useLibrary 'org.apache.http.legacy'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('test')
androidTest {
manifest.srcFile 'test/AndroidManifest.xml'
java.srcDirs = ['test/src']
resources.srcDirs = ['test/src']
aidl.srcDirs = ['test/src']
renderscript.srcDirs = ['test/src']
res.srcDirs = ['test/res']
assets.srcDirs = ['test/assets']
}
}
buildTypes {
// use proguard on debug too since we have unknowingly broken
// release builds before.
@ -167,6 +144,11 @@ android {
targetCompatibility JavaVersion.VERSION_1_7
}
testOptions {
// prevent tests from dying on android.util.Log calls
unitTests.returnDefaultValues = true
}
lintOptions {
checkReleaseBuilds false
abortOnError false

View File

@ -13,6 +13,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class ApkProviderHelperTest extends BaseApkProviderTest {
public void testKnownApks() {

View File

@ -14,6 +14,7 @@ import org.fdroid.fdroid.mock.MockRepo;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class ApkProviderTest extends BaseApkProviderTest {
/**

View File

@ -17,6 +17,7 @@ import mock.MockCategoryResources;
import mock.MockContextSwappableComponents;
import mock.MockInstallablePackageManager;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class AppProviderTest extends FDroidProviderTest<AppProvider> {
public AppProviderTest() {

View File

@ -22,6 +22,7 @@ import mock.MockContextEmptyComponents;
import mock.MockContextSwappableComponents;
import mock.MockFDroidResources;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public abstract class FDroidProviderTest<T extends FDroidProvider> extends ProviderTestCase2MockContext<T> {
private FDroidProvider[] allProviders = {

View File

@ -10,6 +10,7 @@ import org.fdroid.fdroid.data.SanitizedFile;
import java.io.File;
import java.util.UUID;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class FileCompatTest extends InstrumentationTestCase {
private static final String TAG = "FileCompatTest";

View File

@ -10,6 +10,7 @@ import mock.MockInstallablePackageManager;
* For practical reasons, it extends FDroidProviderTest<InstalledAppProvider>, although there is also a
* separate test for the InstalledAppProvider which tests the CRUD operations in more detail.
*/
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class InstalledAppCacheTest extends FDroidProviderTest<InstalledAppProvider> {
private MockInstallablePackageManager packageManager;

View File

@ -9,6 +9,7 @@ import org.fdroid.fdroid.data.RepoProvider;
import mock.MockInstallablePackageManager;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class InstalledAppProviderTest extends FDroidProviderTest<InstalledAppProvider> {
private MockInstallablePackageManager packageManager;

View File

@ -28,6 +28,7 @@ import java.io.File;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class MultiRepoUpdaterTest extends InstrumentationTestCase {
private static final String TAG = "RepoUpdaterTest";

View File

@ -9,6 +9,7 @@ import org.fdroid.fdroid.data.Repo;
import java.io.File;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class RepoUpdaterTest extends InstrumentationTestCase {
private static final String TAG = "RepoUpdaterTest";

View File

@ -24,6 +24,7 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class RepoXMLHandlerTest extends AndroidTestCase {
private static final String TAG = "RepoXMLHandlerTest";

View File

@ -6,6 +6,7 @@ import org.fdroid.fdroid.data.SanitizedFile;
import java.io.File;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class SanitizedFileTest extends AndroidTestCase {
public void testSanitizedFile() {

View File

@ -3,6 +3,7 @@ package org.fdroid.fdroid;
import android.test.AndroidTestCase;
@SuppressWarnings("PMD") // TODO port this to JUnit 4 semantics
public class UtilsTest extends AndroidTestCase {
String fdroidFingerprint = "43238D512C1E5EB2D6569F4A3AFBF5523418B82E0A3ED1552770ABB9A9C9CCAB";

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 887 B

After

Width:  |  Height:  |  Size: 887 B

View File

@ -206,6 +206,9 @@ public class FDroidApp extends Application {
// the database is locked due to the database updater.
InstalledAppCacheUpdater.updateInBackground(getApplicationContext());
// make sure the current proxy stuff is configured
Preferences.get().configureProxy();
// If the user changes the preference to do with filtering rooted apps,
// it is easier to just notify a change in the app provider,
// so that the newly updated list will correctly filter relevant apps.

View File

@ -6,6 +6,9 @@ import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@ -14,6 +17,8 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import info.guardianproject.netcipher.NetCipher;
/**
* Handles shared preferences for FDroid, looking after the names of
* preferences, default values and caching. Needs to be setup in the FDroidApp
@ -178,6 +183,18 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
return preferences.getBoolean(PREF_ENABLE_PROXY, DEFAULT_ENABLE_PROXY);
}
/**
* Configure the proxy settings based on whether its enabled and set up. This must be
* run once at app startup, then whenever any of these settings changes.
*/
public void configureProxy() {
if (isProxyEnabled()) {
// if "Use Tor" is set, NetCipher will ignore these proxy settings
SocketAddress sa = new InetSocketAddress(getProxyHost(), getProxyPort());
NetCipher.setProxy(new Proxy(Proxy.Type.HTTP, sa));
}
}
public String getProxyHost() {
return preferences.getString(PREF_PROXY_HOST, DEFAULT_PROXY_HOST);
}

Some files were not shown because too many files have changed in this diff Show More