robolectric

How to run a Junit5 test with Android dependencies and robolectric

笑着哭i 提交于 2021-02-07 13:15:45
问题 I am trying to run a unit test like that: @org.junit.jupiter.api.Test void junit5codeCoverage() { final int result = new Foo().junit5(); Assert.assertEquals(Looper.getMainLooper().getThread(), Thread.currentThread()); assertEquals(-1, result); } That is a Junit5 test with Android dependencies (i.e Looper.getMainLooper() ) with Robolectric. I am using the junit5 android plugin from mannodermaus that allows running junit5 within Android setups. But this does not work out of the box because it

How To Test PagingData From Paging 3

痴心易碎 提交于 2021-01-29 09:11:11
问题 My ViewModel has a method which returns a flow of PagingData . In my app, the data is fetched from the remote server, which is then saved to Room (the single source of truth): fun getChocolates(): Flow<PagingData<Chocolate>> { val pagingSourceFactory = { dao().getChocolateListData() } return Pager( config = PagingConfig( pageSize = NETWORK_PAGE_SIZE, maxSize = MAX_MEMORY_SIZE, enablePlaceholders = false ), remoteMediator = ChocolateRemoteMediator( api, dao ), pagingSourceFactory =

“RobolectricTestRunner.class” not recognized in Android Studio

不想你离开。 提交于 2020-12-30 05:36:02
问题 I'm trying to use Robolectric to run unit tests but the Android Studio is not recognizing the class on: @RunWith(RobolectricTestRunner.class) Details: classpath 'com.android.tools.build:gradle:3.0.0' And I'm importing dependency: testImplementation "org.robolectric:robolectric:3.5.1" And: android { testOptions { unitTests { includeAndroidResources = true } } } It simply does not appear option to import the class. Should I add any more dependencies I'm forgetting? Error: error: package org

“RobolectricTestRunner.class” not recognized in Android Studio

空扰寡人 提交于 2020-12-30 05:33:21
问题 I'm trying to use Robolectric to run unit tests but the Android Studio is not recognizing the class on: @RunWith(RobolectricTestRunner.class) Details: classpath 'com.android.tools.build:gradle:3.0.0' And I'm importing dependency: testImplementation "org.robolectric:robolectric:3.5.1" And: android { testOptions { unitTests { includeAndroidResources = true } } } It simply does not appear option to import the class. Should I add any more dependencies I'm forgetting? Error: error: package org

Robolectric and Android SDK 29

只愿长相守 提交于 2020-11-26 04:58:21
问题 When will Robolectric be compatible with Android SDK 29? Did I upgraded too early by changing targetSdkVersion and compileSdkVersion to 29? When I run my unit tests I get this huge stacktrace: java.lang.IllegalArgumentException: API level 29 is not available at org.robolectric.plugins.UnknownSdk.getJarPath(UnknownSdk.java:25) at org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader.<init>(AndroidSandbox.java:102) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Robolectric and Android SDK 29

纵饮孤独 提交于 2020-11-26 04:57:50
问题 When will Robolectric be compatible with Android SDK 29? Did I upgraded too early by changing targetSdkVersion and compileSdkVersion to 29? When I run my unit tests I get this huge stacktrace: java.lang.IllegalArgumentException: API level 29 is not available at org.robolectric.plugins.UnknownSdk.getJarPath(UnknownSdk.java:25) at org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader.<init>(AndroidSandbox.java:102) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

AndroidThreeTen not working in unit test without robolectric?

谁都会走 提交于 2020-07-20 21:03:01
问题 I'm having trouble creating a unit test without needing robolectric. I am using AndroidThreeTen.init(this) in my code and when I run my test if I disable robolectric I get an error: org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered and if I leave it enabled I get this: [Robolectric] com.mycomp.,yapp.utilities.log.LogTest.on Calling function w it returns an Int: sdk=28; resources=BINARY I have tried using testImplementation ‘com.jakewharton.threetenabp:threetenabp:1.1

AndroidThreeTen not working in unit test without robolectric?

邮差的信 提交于 2020-07-20 21:00:07
问题 I'm having trouble creating a unit test without needing robolectric. I am using AndroidThreeTen.init(this) in my code and when I run my test if I disable robolectric I get an error: org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered and if I leave it enabled I get this: [Robolectric] com.mycomp.,yapp.utilities.log.LogTest.on Calling function w it returns an Int: sdk=28; resources=BINARY I have tried using testImplementation ‘com.jakewharton.threetenabp:threetenabp:1.1

How to add Java 9 to Android Studio?

六眼飞鱼酱① 提交于 2020-05-14 17:51:11
问题 I am using Robolectric library and the latest version of it v4.3.1 requires Java 9 to run. I am trying to point JRE on edit configurations but I am not finding Java 9 in the drop-down even though I have already installed it. It would be really helpful if somebody can please explain! Please check Java 9 installed. 回答1: You can't use Java 9 , Android only supports till Java 8 . You should use the JDK version that comes with Android Studio, NO need for side alone JDK. The current JDK version is

How to add Java 9 to Android Studio?

狂风中的少年 提交于 2020-05-14 17:51:08
问题 I am using Robolectric library and the latest version of it v4.3.1 requires Java 9 to run. I am trying to point JRE on edit configurations but I am not finding Java 9 in the drop-down even though I have already installed it. It would be really helpful if somebody can please explain! Please check Java 9 installed. 回答1: You can't use Java 9 , Android only supports till Java 8 . You should use the JDK version that comes with Android Studio, NO need for side alone JDK. The current JDK version is