robolectric

Robolectric AndroidX fragments NoClassDefFoundError

吃可爱长大的小学妹 提交于 2020-04-10 07:23:30
问题 After migration of code and tests to AndroidX , all seems to work pretty well, however Robolectric junit tests for two fragments are failing due to NoClassDefFoundError: androidx/fragment/testing/R$style exception. The stack trace: java.lang.NoClassDefFoundError: androidx/fragment/testing/R$style at androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity.onCreate(FragmentScenario.java:79) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation

Robolectric AndroidX fragments NoClassDefFoundError

旧时模样 提交于 2020-04-10 07:21:25
问题 After migration of code and tests to AndroidX , all seems to work pretty well, however Robolectric junit tests for two fragments are failing due to NoClassDefFoundError: androidx/fragment/testing/R$style exception. The stack trace: java.lang.NoClassDefFoundError: androidx/fragment/testing/R$style at androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity.onCreate(FragmentScenario.java:79) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation

Robolectric AndroidX fragments NoClassDefFoundError

时间秒杀一切 提交于 2020-04-10 07:21:07
问题 After migration of code and tests to AndroidX , all seems to work pretty well, however Robolectric junit tests for two fragments are failing due to NoClassDefFoundError: androidx/fragment/testing/R$style exception. The stack trace: java.lang.NoClassDefFoundError: androidx/fragment/testing/R$style at androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity.onCreate(FragmentScenario.java:79) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation

How to resolve duplicated gradle Dependency issues

纵饮孤独 提交于 2020-01-31 03:27:07
问题 I have tried to test my code with robolectric. Problem is that it has duplicated References. e.g. java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1) I have used the gradel artifact app:dependencies to get the following report. Here the important parts: +--- org.robolectric:robolectric:4

Robolectric buildActivity() with Mockito spy?

百般思念 提交于 2020-01-28 10:31:05
问题 It seems to me that building an Activity unit test with Robolectric's lifecycle utilities (starting with Robolectric.buildActivity() ) and spying on the same Activity with a Mockito spy are mutually exclusive. Because buildActivity() controls the construction of the Activity object, the only place to add a spy for the Activity is after calling buildActivity() . However, the spy doesn't function properly when it's added after the fact. This is especially true when spying for side effects of

Mockito runnable: wanted but not invoked?

别说谁变了你拦得住时间么 提交于 2020-01-24 10:03:38
问题 I want to make sure I'm not doing something terribly wrong before I submit a bug report. This is really weird. The setup: robolectric 3.0; mockito 1.10.19 Unit under test: public BbScrollView( Context context ){ this( context, null ); } public BbScrollView( Context context, AttributeSet attrs ) { super( context, attrs ); mScrollTask = new Runnable() { public void run() { checkForStopped(); } }; } public void checkForStopped(){ int newPosition = getScrollY(); // the rest is irrelevant , but I

Gradle Robolectric Resources NotFoundException in Testing

北城以北 提交于 2020-01-21 06:46:29
问题 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 =

Shadowing getFilesDir() in Robolectric 3

我是研究僧i 提交于 2020-01-15 07:15:30
问题 I'd like to shadow Context.getFilesDir() in order to "virtualize" the filesystem my app is running in the test environment, but I can't find the right enclosing class to shadow. I tried shadowing Context : @Implements(Context.class) public class MyShadow extends ShadowContext { private File testRoot; public MyShadow() { testRoot = new File(FileUtils.getTempDirectory(), "androidTestRoot-" + System.currentTimeMillis()); } @Implementation public File getFilesDir() { return new File(testRoot,

How to run Unit test in Realm Db using Roboelectric

只愿长相守 提交于 2020-01-14 14:41:09
问题 I have written a simple test case using for testing Realm db. But I'm always getting error java.lang.UnsatisfiedLinkError: Can't load library: /tmp/android-tmp-robolectric4167396756480823821/app_lib/librealm-jni.so This is my test import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import io.realm.Realm; @RunWith(RobolectricTestRunner.class) public class RealmTest { @Test public void realmShouldWork()

Robolectric does not support API level 28

旧时模样 提交于 2020-01-13 07:53:08
问题 Although this question has been answered for previous versions in other threads, none of the answers seems to work for me with api 28 right now so.. All Robolectric tests worked fine when on api 27. Now when my app api target is 28 they all fail. I have @Config(constants = BuildConfig::class, sdk = [Build.VERSION_CODES.P]) on my test class. Diving into Robolectrics internal SdkConfig.java it looks like they add support for api 28: addSdk(Build.VERSION_CODES.P, "P", "4651975", "P"); But when