1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Merge pull request #652 from k9mail/gradle_unit_test_support

Gradle unit test support
This commit is contained in:
Jan Berkel 2015-06-03 10:19:45 +01:00
commit 270d22681f
31 changed files with 115 additions and 89 deletions

View File

@ -4,7 +4,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.0.0' classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
} }
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<lint> <lint>
<issue id="MissingTranslation" severity="ignore" /> <issue id="MissingTranslation" severity="ignore" />
<issue id="OldTargetApi" severity="ignore" />
<!-- Transifex and Lint disagree on what quantities are necessary --> <!-- Transifex and Lint disagree on what quantities are necessary -->
<issue id="UnusedQuantity" severity="warning"> <issue id="UnusedQuantity" severity="warning">

View File

@ -1,14 +1,29 @@
apply plugin: 'findbugs' apply plugin: 'findbugs'
check.dependsOn 'findbugs' afterEvaluate {
task findbugs(type: FindBugs, dependsOn: ['compileDebugJava', 'compileDebugTestJava']) { def variants = plugins.hasPlugin('com.android.application') ?
ignoreFailures = true android.applicationVariants : android.libraryVariants
classes = fileTree('build/intermediates/classes/debug/') +
fileTree('build/intermediates/classes/test/debug/') variants.each { variant ->
source = project.android.sourceSets.main.java.getSrcDirs() + def task = project.task("findBugs${variant.name.capitalize()}", type: FindBugs) {
project.android.sourceSets.androidTest.java.getSrcDirs() group = 'verification'
classpath = files() description = "Run FindBugs for the ${variant.description}."
effort = 'max' effort = 'max'
ignoreFailures = true
includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml") includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml")
excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml")
def variantCompile = variant.javaCompile
classes = fileTree(variantCompile.destinationDir)
source = variantCompile.source
classpath = variantCompile.classpath.plus(project.files(android.bootClasspath))
dependsOn(variantCompile)
}
tasks.getByName('check').dependsOn(task)
}
} }

View File

@ -1,6 +1,7 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply from: '../gradle/plugins/checkstyle-android.gradle' apply from: '../gradle/plugins/checkstyle-android.gradle'
apply from: '../gradle/plugins/findbugs-android.gradle' apply from: '../gradle/plugins/findbugs-android.gradle'
apply plugin: 'jacoco'
repositories { repositories {
jcenter() jcenter()
@ -12,6 +13,17 @@ dependencies {
compile 'commons-io:commons-io:2.4' compile 'commons-io:commons-io:2.4'
compile 'com.jcraft:jzlib:1.0.7' compile 'com.jcraft:jzlib:1.0.7'
compile 'com.beetstra.jutf7:jutf7:1.0.0' compile 'com.beetstra.jutf7:jutf7:1.0.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0'
testCompile('org.robolectric:robolectric:3.0-rc3') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile('junit:junit:4.10') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
} }
android { android {
@ -21,6 +33,14 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 21 targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
testCoverageEnabled rootProject.testCoverage
}
} }
lintOptions { lintOptions {
@ -40,5 +60,6 @@ android {
exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
} }
} }

View File

@ -2,10 +2,15 @@ package com.fsck.k9.mail;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class AddressTest { public class AddressTest {
/** /**
* test the possibility to parse "From:" fields with no email. * test the possibility to parse "From:" fields with no email.

View File

@ -2,10 +2,15 @@ package com.fsck.k9.mail;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class Address_quoteAtoms { public class Address_quoteAtoms {
@Test @Test
public void testNoQuote() { public void testNoQuote() {

View File

@ -2,10 +2,15 @@ package com.fsck.k9.mail.internet;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class CharsetSupportTest { public class CharsetSupportTest {
@Test @Test

View File

@ -2,10 +2,15 @@ package com.fsck.k9.mail.internet;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class DecoderUtilTest { public class DecoderUtilTest {
@Test @Test

View File

@ -18,10 +18,15 @@ import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.BodyPart;
import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.Multipart; import com.fsck.k9.mail.Multipart;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MimeMessageParseTest { public class MimeMessageParseTest {
@Before @Before
public void setup() { public void setup() {

View File

@ -3,6 +3,9 @@ package com.fsck.k9.mail.store.imap;
import com.fsck.k9.mail.filter.PeekableInputStream; import com.fsck.k9.mail.filter.PeekableInputStream;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@ -16,6 +19,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ImapResponseParserTest { public class ImapResponseParserTest {
@Test public void testSimpleOkResponse() throws IOException { @Test public void testSimpleOkResponse() throws IOException {

View File

@ -18,12 +18,17 @@
package com.fsck.k9.mail.store.imap; package com.fsck.k9.mail.store.imap;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class ImapUtilityTest { public class ImapUtilityTest {
@Test @Test
public void testGetImapSequenceValues() { public void testGetImapSequenceValues() {

View File

@ -2,6 +2,7 @@ apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply from: '../gradle/plugins/checkstyle-android.gradle' apply from: '../gradle/plugins/checkstyle-android.gradle'
apply from: '../gradle/plugins/findbugs-android.gradle' apply from: '../gradle/plugins/findbugs-android.gradle'
apply plugin: 'jacoco'
repositories { repositories {
jcenter() jcenter()
@ -24,7 +25,14 @@ dependencies {
androidTestCompile('com.icegreen:greenmail:1.4.1') { androidTestCompile('com.icegreen:greenmail:1.4.1') {
exclude group: 'junit' exclude group: 'junit'
} }
androidTestCompile 'com.madgag.spongycastle:pg:1.51.0.0'
testCompile('org.robolectric:robolectric:3.0-rc3') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile('junit:junit:4.10') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
} }
android { android {

View File

@ -1,12 +1,12 @@
package com.fsck.k9.activity; package com.fsck.k9.activity;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.mail.Flag; import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
@ -14,7 +14,8 @@ import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MessageReferenceTest { public class MessageReferenceTest {
@Test @Test

View File

@ -3,8 +3,6 @@ package com.fsck.k9.crypto;
import java.util.List; import java.util.List;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.mail.Part; import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.internet.MimeBodyPart; import com.fsck.k9.mail.internet.MimeBodyPart;
import com.fsck.k9.mail.internet.MimeMessage; import com.fsck.k9.mail.internet.MimeMessage;
@ -13,12 +11,15 @@ import com.fsck.k9.mail.internet.MimeMultipart;
import com.fsck.k9.mail.internet.TextBody; import com.fsck.k9.mail.internet.TextBody;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertSame; import static junit.framework.Assert.assertSame;
@RunWith(AndroidJUnit4.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MessageDecryptVerifierTest { public class MessageDecryptVerifierTest {
@Test @Test

View File

@ -1,18 +1,20 @@
package com.fsck.k9.helper; package com.fsck.k9.helper;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class HtmlConverterTest { public class HtmlConverterTest {
// Useful if you want to write stuff to a file for debugging in a browser. // Useful if you want to write stuff to a file for debugging in a browser.
private static final boolean WRITE_TO_FILE = Boolean.parseBoolean(System.getProperty("k9.htmlConverterTest.writeToFile", "false")); private static final boolean WRITE_TO_FILE = Boolean.parseBoolean(System.getProperty("k9.htmlConverterTest.writeToFile", "false"));

View File

@ -3,27 +3,29 @@ package com.fsck.k9.helper;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.text.SpannableString; import android.text.SpannableString;
import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Address;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class MessageHelperTest { public class MessageHelperTest {
private Contacts contacts; private Contacts contacts;
private Contacts mockContacts; private Contacts mockContacts;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Context context = InstrumentationRegistry.getTargetContext(); Context context = RuntimeEnvironment.application;
contacts = new Contacts(context); contacts = new Contacts(context);
mockContacts = new Contacts(context) { mockContacts = new Contacts(context) {
@Override public String getNameForAddress(String address) { @Override public String getNameForAddress(String address) {

View File

@ -3,6 +3,7 @@ package com.fsck.k9.message;
import com.fsck.k9.Account.QuoteStyle; import com.fsck.k9.Account.QuoteStyle;
import com.fsck.k9.mail.internet.TextBody; import com.fsck.k9.mail.internet.TextBody;
import org.junit.Ignore;
import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory; import org.junit.experimental.theories.Theory;
@ -12,6 +13,8 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
//TODO: Get rid of 'Theories' and write simple tests
@Ignore
@RunWith(Theories.class) @RunWith(Theories.class)
public class TextBodyBuilderTest { public class TextBodyBuilderTest {

View File

@ -3,4 +3,3 @@ include ':k9mail-library'
include ':plugins:Android-PullToRefresh:library' include ':plugins:Android-PullToRefresh:library'
include ':plugins:HoloColorPicker' include ':plugins:HoloColorPicker'
include ':plugins:openpgp-api-library' include ':plugins:openpgp-api-library'
include ':tests-on-jvm'

View File

@ -1,39 +0,0 @@
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
dependencies {
testCompile project(':k9mail')
testCompile 'junit:junit:4.12'
}
sourceSets {
test {
compileClasspath += files(project(':k9mail').compileDebugJava.destinationDir)
compileClasspath += project(':k9mail').compileDebugJava.classpath
runtimeClasspath += files(project(':k9mail').compileDebugJava.destinationDir)
runtimeClasspath += project(':k9mail').compileDebugJava.classpath
}
}
checkstyle {
ignoreFailures = true
configFile file("$rootProject.projectDir/config/checkstyle/checkstyle.xml")
}
findbugs {
ignoreFailures = true
effort = 'max'
includeFilter = file("$rootProject.projectDir/config/findbugs/include_filter.xml")
excludeFilter = file("$rootProject.projectDir/config/findbugs/exclude_filter.xml")
}
check.dependsOn 'checkstyleTest'
check.dependsOn 'findbugsTest'
compileTestJava.dependsOn ':k9mail:compileDebugJava'

View File

@ -1,7 +0,0 @@
package android.text;
public class TextUtils {
public static boolean isEmpty(CharSequence str) {
return (str == null || str.length() == 0);
}
}

View File

@ -1,11 +0,0 @@
package android.util;
public class Log {
public static int v(String tag, String message) { return 0; }
public static int d(String tag, String message) { return 0; }
public static int d(String tag, String message, Throwable throwable) { return 0; }
public static int i(String tag, String message) { return 0; }
public static int w(String tag, String message) { return 0; }
public static int e(String tag, String message) { return 0; }
public static int e(String tag, String message, Throwable th) { return 0; }
}

View File

@ -1,5 +0,0 @@
package com.fsck.k9;
public class K9 {
public static boolean DEBUG = false;
}