From e7fa124108e72b0eaaa1319467d666d876278467 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 May 2014 22:18:11 +0200 Subject: update unit test support in build files --- OpenKeychain/build.gradle | 59 +++++++++------------- .../src/androidTest/java/tests/SomeTest.java | 12 +++++ .../keychain/PgpKeyOperationTest.java | 46 ----------------- .../keychain/RobolectricGradleTestRunner.java | 23 --------- build.gradle | 1 + 5 files changed, 36 insertions(+), 105 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/tests/SomeTest.java delete mode 100644 OpenKeychain/src/test/java/org/sufficientlysecure/keychain/PgpKeyOperationTest.java delete mode 100644 OpenKeychain/src/test/java/org/sufficientlysecure/keychain/RobolectricGradleTestRunner.java diff --git a/OpenKeychain/build.gradle b/OpenKeychain/build.gradle index 090a7a2bf..11dd7f21c 100644 --- a/OpenKeychain/build.gradle +++ b/OpenKeychain/build.gradle @@ -1,9 +1,11 @@ apply plugin: 'android' +apply plugin: 'android-test' sourceSets { - testLocal { + androidTest { java.srcDir file('src/test/java') - resources.srcDir file('src/test/resources') + // configure the set of classes for JUnit tests + // include '**/*Test.class' } } @@ -23,24 +25,25 @@ dependencies { compile project(':extern:spongycastle:prov') compile project(':extern:AppMsg:library') - // Dependencies for the `testLocal` task, make sure to list all your global dependencies here as well - testLocalCompile 'junit:junit:4.11' - testLocalCompile 'org.robolectric:robolectric:2.2' - testLocalCompile 'com.google.android:android:4.1.1.4' - testLocalCompile 'com.android.support:support-v4:19.1.0' - testLocalCompile 'com.android.support:appcompat-v7:19.1.0' - testLocalCompile project(':extern:openpgp-api-lib') - testLocalCompile project(':extern:openkeychain-api-lib') - testLocalCompile project(':extern:html-textview') - testLocalCompile project(':extern:StickyListHeaders:library') - testLocalCompile project(':extern:AndroidBootstrap:AndroidBootstrap') - testLocalCompile project(':extern:zxing-qr-code') - testLocalCompile project(':extern:zxing-android-integration') - testLocalCompile project(':extern:spongycastle:core') - testLocalCompile project(':extern:spongycastle:pg') - testLocalCompile project(':extern:spongycastle:pkix') - testLocalCompile project(':extern:spongycastle:prov') - testLocalCompile project(':extern:AppMsg:library') + // Dependencies for the `instrumentTest` task, make sure to list all your global dependencies here as well + androidTestCompile 'junit:junit:4.10' + androidTestCompile 'org.robolectric:robolectric:2.1.+' + androidTestCompile 'com.squareup:fest-android:1.0.+' + androidTestCompile 'com.google.android:android:4.1.1.4' + androidTestCompile 'com.android.support:support-v4:19.1.0' + androidTestCompile 'com.android.support:appcompat-v7:19.1.0' + androidTestCompile project(':extern:openpgp-api-lib') + androidTestCompile project(':extern:openkeychain-api-lib') + androidTestCompile project(':extern:html-textview') + androidTestCompile project(':extern:StickyListHeaders:library') + androidTestCompile project(':extern:AndroidBootstrap:AndroidBootstrap') + androidTestCompile project(':extern:zxing-qr-code') + androidTestCompile project(':extern:zxing-android-integration') + androidTestCompile project(':extern:spongycastle:core') + androidTestCompile project(':extern:spongycastle:pg') + androidTestCompile project(':extern:spongycastle:pkix') + androidTestCompile project(':extern:spongycastle:prov') + androidTestCompile project(':extern:AppMsg:library') } android { @@ -92,20 +95,6 @@ android { } } -task localTest(type: Test, dependsOn: assemble) { - testClassesDir = sourceSets.testLocal.output.classesDir - - android.sourceSets.main.java.srcDirs.each { dir -> - def buildDir = dir.getAbsolutePath().split("\\" + File.separator) - buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join("\\" + File.separator) - - sourceSets.testLocal.compileClasspath += files(buildDir) - sourceSets.testLocal.runtimeClasspath += files(buildDir) - } - - classpath = sourceSets.testLocal.runtimeClasspath -} - // NOTE: This disables Lint! tasks.whenTaskAdded { task -> if (task.name.equals("lint")) { @@ -113,5 +102,3 @@ tasks.whenTaskAdded { task -> } } -// NOTE: tests disabled! -//check.dependsOn localTest diff --git a/OpenKeychain/src/androidTest/java/tests/SomeTest.java b/OpenKeychain/src/androidTest/java/tests/SomeTest.java new file mode 100644 index 000000000..edf5f7bcc --- /dev/null +++ b/OpenKeychain/src/androidTest/java/tests/SomeTest.java @@ -0,0 +1,12 @@ +package tests; + +import org.junit.Assert; +import org.junit.Test; + +public class SomeTest { + @Test + public void willFail() { + // stub + // Assert.assertThat(); + } +} \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/PgpKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/PgpKeyOperationTest.java deleted file mode 100644 index 72f29a1e3..000000000 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/PgpKeyOperationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.sufficientlysecure.keychain; - -import org.junit.Before; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.Robolectric; - -import org.sufficientlysecure.keychain.pgp.*; -import org.spongycastle.openpgp.*; - -@RunWith(RobolectricGradleTestRunner.class) -public class PgpKeyOperationTest { - - PGPSecretKey key; - - @Before - public void setUp() throws Exception { - - /* Input */ - int algorithm = Id.choice.algorithm.dsa; - String passphrase = "swag"; - int keysize = 2048; - boolean masterKey = true; - - /* Operation */ - PgpKeyOperation keyOperations = new PgpKeyOperation(null); - key = keyOperations.createKey(algorithm, keysize, passphrase, masterKey); - - System.err.println("initialized, test key: " + PgpKeyHelper.convertKeyIdToHex(key.getKeyID())); - } - - @After - public void tearDown() { - } - - @Test - public void createTest() { - } - - @Test - public void certifyKey() { - System.err.println("swag"); - } - -} diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/RobolectricGradleTestRunner.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/RobolectricGradleTestRunner.java deleted file mode 100644 index b64ffde07..000000000 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/RobolectricGradleTestRunner.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sufficientlysecure.keychain; - -import org.junit.runners.model.InitializationError; -import org.robolectric.AndroidManifest; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; -import org.robolectric.res.Fs; -import org.robolectric.res.FsFile; - -import org.sufficientlysecure.keychain.KeychainApplication; - -public class RobolectricGradleTestRunner extends RobolectricTestRunner { - public RobolectricGradleTestRunner(Class testClass) throws InitializationError { - super(testClass); - } - - @Override protected AndroidManifest getAppManifest(Config config) { - String myAppPath = KeychainApplication.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - String manifestPath = myAppPath + "../../../src/main/AndroidManifest.xml"; - return createAppManifest(Fs.fileFromPath(manifestPath)); - } -} - diff --git a/build.gradle b/build.gradle index dc6f12f08..c9106d957 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:0.10.0' + classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+' } } -- cgit v1.2.3