robolectric

Testing with SugarORM and Robolectric

拈花ヽ惹草 提交于 2019-12-01 06:15:41
问题 I trying to setup an testing environment for my android project. The basic Robolectric setup is done. I used this nice tutorial. If I comment out SugarORM in my Manifest.xml, all test works fine. But If I want to use it with SugarORM I always get this error: java.lang.NullPointerException at dalvik.system.DexFile$DFEnum.hasMoreElements(DexFile.java:239) at com.orm.SugarDb.getDomainClasses(SugarDb.java:37) at com.orm.SugarDb.createDatabase(SugarDb.java:104) at com.orm.SugarDb.onCreate(SugarDb

Robolectric accessing database throws an error

久未见 提交于 2019-12-01 04:19:51
问题 I have a test that creates an activity which attempts to get some data from the database. This fails with SQLiteException 17:40:40.528 [DEBUG] [TestEventLogger] android.database.sqlite.SQLiteException: Cannot open SQLite connection, base error code: 14 17:40:40.528 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection.rethrow(ShadowSQLiteConnection.java:53) 17:40:40.528 [DEBUG] [TestEventLogger] at org.robolectric.shadows.ShadowSQLiteConnection.access$600

Gradle Robolectric Resources NotFoundException in Testing

隐身守侯 提交于 2019-12-01 03:53:14
I've already knew that this issue has been asked before but I can't solve this problem. I am able to compile and apply test with jUnit, Robolectric and Gradle. The issue or error comes when I try to test an Activity or get a resource. Every time I've got the same issue: android.content.res.Resources$NotFoundException: unknown resource Resources$NotFoundException: no such theme PageActivity startPageActivity = Robolectric.buildActivity(PageActivity.class).create().get(); Context context = Robolectric.getShadowApplication().getApplicationContext(); ShadowContext shadowContext = shadowOf(context)

How to specify classpath ordering in Gradle

大憨熊 提交于 2019-12-01 02:58:41
I need to control the ordering of jars in the testRuntime configuration. I must make sure that robolectric-x.x.jar comes before android.jar, or else I get the dreaded RuntimeException("Stub!"). How do I do that? Olle Hallin Here is my complete build.gradle for running Robolectric tests against my Android app, which uses RoboGuice: apply plugin: 'java' androidJar = new File(System.getenv('ANDROID_HOME'), '/platforms/android-7/android.jar') configurations { robo } dependencies { robo('com.pivotallabs:robolectric:1.0-RC1') testCompile('org.roboguice:roboguice:1.1.2') testCompile('junit:junit:4.8

Android TDD: The saga continues with Robolectric & Gradle

戏子无情 提交于 2019-12-01 00:28:23
Just when I'd achieved an effective development and build environment with the android-maven-plugin , the new kid on the block, Gradle, starts making inroads into the Android circles. Not being hot on Groovy and with the android-gradle plugin almost as fragmented as the OS itself I've hit some issues. Specifically around building library projects, with flavours and our buddy Robolectric . Short version I am at a loss as to what my next move should be upon encountering the gradle error; Cannot add a SourceSet with name 'testDebug' as a SourceSet with that name already exists. The error emanates

getSystemService in Robolectric returns object with null Context

自古美人都是妖i 提交于 2019-11-30 22:57:51
In my activity's onCreate I have: AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); When testing the activity with Robolectric I create it with ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class); MainActivity activity = controller.attach().create().get(); The AudioManager is then created but with mContext = null which leads to a NullPointerException when calling registerMediaButtonEventReceiver on it because that framework method uses the context internally. Is there any way to make sure the AudioManager is created with

How to mock Dagger activity object graphs?

对着背影说爱祢 提交于 2019-11-30 22:46:08
I'm using Dagger in an android app to provide application and activity scope graphs. And I'm using Robolectric for unit-testing. I know that I can provide Robolectric with a substitute Application class that is configured with an application object graph that overrides the real one with mocks. But I'm stumped as to how to do the same with the activity object graphs since the standard pattern for activity object graphs is for the activities themselves to instantiate the activity-specific Dagger module they need. Any suggestions would be greatly appreciated. Please take a look to my project -

Android - Jacoco code coverage ignores Robolectric tests

柔情痞子 提交于 2019-11-30 19:48:44
Trying to get Code coverage on my Robolectric tests in Android utilising Jacoco but it simply refuses to acknowledge my Robolectric tests when creating the reports. My jacoco.gradle file is as follows: apply plugin: 'jacoco' jacoco { toolVersion = "0.7.6.201602180812" } project.afterEvaluate { android.applicationVariants.all { variant -> def name = variant.name def testTaskName = "test${name.capitalize()}UnitTest" tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") { group = "Reporting" description = "Generate Jacoco coverage reports for the ${name

Android TDD: The saga continues with Robolectric & Gradle

自古美人都是妖i 提交于 2019-11-30 18:20:27
问题 Just when I'd achieved an effective development and build environment with the android-maven-plugin , the new kid on the block, Gradle, starts making inroads into the Android circles. Not being hot on Groovy and with the android-gradle plugin almost as fragmented as the OS itself I've hit some issues. Specifically around building library projects, with flavours and our buddy Robolectric . Short version I am at a loss as to what my next move should be upon encountering the gradle error; Cannot

How to mock Dagger activity object graphs?

江枫思渺然 提交于 2019-11-30 17:43:40
问题 I'm using Dagger in an android app to provide application and activity scope graphs. And I'm using Robolectric for unit-testing. I know that I can provide Robolectric with a substitute Application class that is configured with an application object graph that overrides the real one with mocks. But I'm stumped as to how to do the same with the activity object graphs since the standard pattern for activity object graphs is for the activities themselves to instantiate the activity-specific