use mock realm in tests

This commit is contained in:
Phillip Thelen 2017-05-24 15:38:57 +02:00
parent fb18520da6
commit dbfa12c830
5 changed files with 43 additions and 4 deletions

View file

@ -126,9 +126,9 @@ dependencies {
testCompile "junit:junit:4.10"
testCompile "org.assertj:assertj-core:1.7.0"
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile "org.robolectric:robolectric:3.2"
testCompile 'org.robolectric:shadows-multidex:3.1'
testCompile "org.robolectric:shadows-support-v4:3.1"
testCompile "org.robolectric:robolectric:3.3.2"
testCompile 'org.robolectric:shadows-multidex:3.3.2'
testCompile "org.robolectric:shadows-support-v4:3.3.2"
testCompile "org.mockito:mockito-core:1.10.19"
//Leak Detection

View file

@ -58,7 +58,7 @@ public class RepositoryModule {
}
@Provides
Realm providesRealm() {
public Realm providesRealm() {
return Realm.getDefaultInstance();
}

View file

@ -0,0 +1,20 @@
package com.habitrpg.android.habitica;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.components.DaggerAppComponent;
import com.habitrpg.android.habitica.modules.AppModule;
public class TestApplication extends HabiticaBaseApplication {
@Override
protected AppComponent initDagger() {
return DaggerAppComponent.builder()
.appModule(new AppModule(this))
.developerModule(new DebugDeveloperModule())
.repositoryModule(new TestRepositoryModule())
.build();
}
@Override
protected void setupRealm() {
}
}

View file

@ -0,0 +1,18 @@
package com.habitrpg.android.habitica;
import com.habitrpg.android.habitica.modules.RepositoryModule;
import org.mockito.Mockito;
import dagger.Provides;
import io.realm.Realm;
class TestRepositoryModule extends RepositoryModule {
@Provides
@Override
public Realm providesRealm() {
return Mockito.mock(Realm.class);
}
}

View file

@ -1,3 +1,4 @@
sdk=21
packageName=com.habitrpg.android.habitica
manifest=AndroidManifest.xml
application=comh.habitrpg.android.habitica.TestApplication