From 9e638859843ce0b941b44d38fb4f203b5dead71a Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 18 Nov 2014 00:08:25 -0500 Subject: [PATCH] Strange errors in Robolectric land... --- app-test/build.gradle | 13 ++++--- .../downloader/BookListFragmentTest.java | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 app-test/src/test/java/org/bspeice/minimalbible/test/activity/downloader/BookListFragmentTest.java diff --git a/app-test/build.gradle b/app-test/build.gradle index c01d439..c8abb20 100644 --- a/app-test/build.gradle +++ b/app-test/build.gradle @@ -15,16 +15,19 @@ buildscript { } def androidModule = project(':app') -def firstVariant = androidModule.android.applicationVariants.toList().first() +def firstAppVariant = androidModule.android.applicationVariants.toList().first() +//def firstTestVariant = androidModule.android.testVariants.toList().first() dependencies { compile androidModule - testCompile firstVariant.javaCompile.classpath - testCompile firstVariant.javaCompile.outputs.files + testCompile firstAppVariant.javaCompile.classpath + testCompile firstAppVariant.javaCompile.outputs.files + //testCompile firstTestVariant.javaCompile.outputs.files testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath()) testCompile 'junit:junit:4.+' + testCompile 'org.mockito:mockito-all:+' testCompile 'org.robolectric:robolectric:+' } @@ -42,11 +45,11 @@ jacocoTestReport { def jacocoExcludes = [ "android/**/*" ] - firstVariant.javaCompile.exclude(jacocoExcludes).outputs.files + firstAppVariant.javaCompile.exclude(jacocoExcludes).outputs.files doFirst { sourceDirectories = files(androidModule.android.sourceSets.main.java.srcDirs) - classDirectories = firstVariant.javaCompile.outputs.files + classDirectories = firstAppVariant.javaCompile.outputs.files } // Back to your regularly scheduled Jacoco diff --git a/app-test/src/test/java/org/bspeice/minimalbible/test/activity/downloader/BookListFragmentTest.java b/app-test/src/test/java/org/bspeice/minimalbible/test/activity/downloader/BookListFragmentTest.java new file mode 100644 index 0000000..26a3d51 --- /dev/null +++ b/app-test/src/test/java/org/bspeice/minimalbible/test/activity/downloader/BookListFragmentTest.java @@ -0,0 +1,37 @@ +package org.bspeice.minimalbible.test.activity.downloader; + +import org.bspeice.minimalbible.activity.downloader.BookListFragment; +import org.bspeice.minimalbible.activity.downloader.DownloadActivity; +import org.crosswire.jsword.book.BookCategory; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import static org.junit.Assert.assertTrue; + +/** + * Created by bspeice on 11/17/14. + */ +@RunWith(RobolectricTestRunner.class) +@Config(emulateSdk = 18, manifest = "../app/src/main/AndroidManifest.xml") +public class BookListFragmentTest { + + @Before + public void setUp() { + DownloadActivity activity = Robolectric.buildActivity(DownloadActivity.class) + .create().start().visible().get(); + BookListFragment fragment = BookListFragment.newInstance(BookCategory.BIBLE); + activity.getSupportFragmentManager() + .beginTransaction() + .add(fragment, null) + .commit(); + } + + @Test + public void testItsWorking() { + assertTrue(true); + } +}