test: add junit+robolectric to buildfiles and stub test file

This commit is contained in:
Vincent Breitmoser 2014-03-22 14:57:08 +01:00
parent 6f36b72eee
commit 62388e3fdb
4 changed files with 112 additions and 1 deletions

View File

@ -1,5 +1,12 @@
apply plugin: 'android'
sourceSets {
testLocal {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/resources')
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
@ -15,6 +22,25 @@ dependencies {
compile project(':libraries:spongycastle:pkix')
compile project(':libraries:spongycastle:prov')
compile project(':libraries:Android-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.1.+'
testLocalCompile 'com.google.android:android:4.1.1.4'
testLocalCompile 'com.android.support:support-v4:19.0.1'
testLocalCompile 'com.android.support:appcompat-v7:19.0.1'
testLocalCompile project(':OpenPGP-Keychain-API:libraries:openpgp-api-library')
testLocalCompile project(':OpenPGP-Keychain-API:libraries:openkeychain-api-library')
testLocalCompile project(':libraries:HtmlTextView')
testLocalCompile project(':libraries:StickyListHeaders:library')
testLocalCompile project(':libraries:AndroidBootstrap')
testLocalCompile project(':libraries:zxing')
testLocalCompile project(':libraries:zxing-android-integration')
testLocalCompile project(':libraries:spongycastle:core')
testLocalCompile project(':libraries:spongycastle:pg')
testLocalCompile project(':libraries:spongycastle:pkix')
testLocalCompile project(':libraries:spongycastle:prov')
testLocalCompile project(':libraries:Android-AppMsg:library')
}
android {
@ -61,3 +87,19 @@ android {
htmlOutput file("lint-report.html")
}
}
task localTest(type: Test, dependsOn: assemble) {
testClassesDir = sourceSets.testLocal.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
sourceSets.testLocal.compileClasspath += files(buildDir)
sourceSets.testLocal.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.testLocal.runtimeClasspath
}
check.dependsOn localTest

View File

@ -6,7 +6,7 @@
android:orientation="vertical" >
<LinearLayout
android:id="@+android:id/text_layout"
android:id="@+id/text_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"

View File

@ -0,0 +1,46 @@
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");
}
}

View File

@ -0,0 +1,23 @@
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));
}
}