mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-16 04:58:26 -05:00
Prettify the unit testing
This commit is contained in:
parent
b19b740c43
commit
1c15767d10
@ -42,7 +42,7 @@ android {
|
||||
buildToolsVersion '20'
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
manifest.srcFile 'src/main/AndroidManifest.xml'
|
||||
java.srcDirs = ['src/main/java']
|
||||
resources.srcDirs = ['src/main/res']
|
||||
aidl.srcDirs = ['src']
|
||||
@ -52,7 +52,12 @@ android {
|
||||
}
|
||||
|
||||
// Move the tests to tests/java, tests/res, etc...
|
||||
androidTest.setRoot('src/test')
|
||||
androidTest {
|
||||
manifest.srcFile 'src/test/AndroidManifest.xml'
|
||||
java.srcDirs = ['src/test/java']
|
||||
resources.srcDirs = ['src/test/res']
|
||||
assets.srcDirs = ['src/test/assets']
|
||||
}
|
||||
|
||||
// Move the build types to build-types/<type>
|
||||
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
|
||||
|
19
MinimalBible/src/test/AndroidManifest.xml
Normal file
19
MinimalBible/src/test/AndroidManifest.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.bspeice.minimalbible">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="8"
|
||||
android:targetSdkVersion="20" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme"
|
||||
android:name="org.bspeice.minimalbible.test.MinimalBibleTest" >
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,20 @@
|
||||
package org.bspeice.minimalbible.test;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Master module for MinimalBible
|
||||
*/
|
||||
@Module(
|
||||
injects = {
|
||||
MinimalBible.class
|
||||
},
|
||||
includes = {
|
||||
MinimalBibleModules.class
|
||||
}
|
||||
)
|
||||
public class MinimalBibleModulesTest {
|
||||
}
|
@ -1,42 +1,75 @@
|
||||
package org.bspeice.minimalbible.test;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.content.Context;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
public class MinimalBibleTest extends MinimalBible {
|
||||
|
||||
/**
|
||||
* Tests for the Download activity
|
||||
*/
|
||||
public class MinimalBibleTest extends InstrumentationTestCase {
|
||||
/**
|
||||
* The graph used by Dagger to track dependencies
|
||||
*/
|
||||
private ObjectGraph graph;
|
||||
|
||||
@Module(addsTo = MinimalBibleModules.class,
|
||||
injects = MinimalBibleTest.class)
|
||||
public static class DownloadActivityTestModule {}
|
||||
/**
|
||||
* A singleton reference to the Application currently being run.
|
||||
* Used mostly so we have a fixed point to get the App Context from
|
||||
*/
|
||||
private static MinimalBibleTest instance;
|
||||
|
||||
public void setUp() {
|
||||
MinimalBible application = MinimalBible.getApplication();
|
||||
ObjectGraph graph = application.getObjGraph();
|
||||
ObjectGraph plusGraph = graph.plus(DownloadActivityTestModule.class);
|
||||
plusGraph.inject(this);
|
||||
private String TAG = "MinimalBibleTest";
|
||||
|
||||
/**
|
||||
* Create the application, and persist the application Context
|
||||
*/
|
||||
public MinimalBibleTest() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Application Context. Please note, all attempts to get the App Context should come
|
||||
* through here, and please be sure that the Application won't satisfy what you need.
|
||||
* @return The Application Context
|
||||
*/
|
||||
public static Context getAppContext() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* If we've made it to the actual test, injection seems to be working correctly.
|
||||
* Get the Application, rather than just the Application Context. You likely should be using
|
||||
* this, rather than {@link #getAppContext()}
|
||||
* @return The MinimalBible {@link android.app.Application} object
|
||||
*/
|
||||
public void testBasicInjection() {
|
||||
assertEquals(true, true);
|
||||
public static MinimalBibleTest getApplication() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the {@link android.app.Application}. Responsible for building and
|
||||
* holding on to the master ObjectGraph.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
//TODO: Is this necessary?
|
||||
inject(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject a Dagger object
|
||||
* @param o The object to be injected
|
||||
*/
|
||||
@Override
|
||||
public void inject(Object o) {
|
||||
getObjGraph().inject(o);
|
||||
}
|
||||
|
||||
public ObjectGraph getObjGraph() {
|
||||
if (graph == null) {
|
||||
graph = ObjectGraph.create(MinimalBibleModulesTest.class);
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,31 @@
|
||||
package org.bspeice.minimalbible.test.activities.downloader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.ActivityUnitTestCase;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import org.bspeice.minimalbible.MinimalBible;
|
||||
import org.bspeice.minimalbible.MinimalBibleModules;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activities.downloader.ActivityDownloaderModule;
|
||||
import org.bspeice.minimalbible.test.MinimalBibleModulesTest;
|
||||
import org.bspeice.minimalbible.activities.downloader.BookListFragment;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadActivity;
|
||||
import org.bspeice.minimalbible.activities.downloader.DownloadPrefs;
|
||||
import org.crosswire.jsword.book.BookCategory;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.ObjectGraph;
|
||||
import dagger.Provides;
|
||||
import de.devland.esperandro.Esperandro;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 6/23/14.
|
||||
*/
|
||||
public class BookListFragmentTest extends ActivityInstrumentationTestCase2<DownloadActivity> {
|
||||
|
||||
@Module(injects = TestDialogDisplayedIfFirstTimeFragment.class,
|
||||
addsTo = ActivityDownloaderModule.class
|
||||
addsTo = MinimalBibleModulesTest.class
|
||||
)
|
||||
protected static class BookListFragmentTestModule{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user