robolectric-gradle-plugin

How to use findViewById() in robolectric

被刻印的时光 ゝ 提交于 2019-11-30 07:27:58
I simply want to test with robolectric if a certain view is visible in a fragment. My unit test looks like this: ActivityController controller = Robolectric.buildActivity(FragmentActivity.class); FragmentActivity activity = (FragmentActivity) controller.create().start().resume().visible().get(); F fragment = new MyFragment(); activity.getSupportFragmentManager().beginTransaction() .add(fragment, FRAGMENT_TAG).commit(); View view = fragment.getView().findViewById(R.id.my_view); assertEquals(view.getVisibility(), View.VISIBLE); I'm using the latest android gradle plugin 1.1.3, robolectirc 2.4

Android Studio + Robolectric + Gradle Class Not Found Exception

。_饼干妹妹 提交于 2019-11-30 02:46:14
问题 I downloaded Robolectric deckard-gradle project from https://github.com/robolectric/deckard-gradle and imported to Android Studio. On my first run i got !!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) at junit.textui.TestRunner.<init>(TestRunner.java:54) at junit.textui.TestRunner.<init>(TestRunner.java:48) at junit.textui.TestRunner.<init>(TestRunner.java:41) Error and i fixed this from .iml. Then i got:

Resources$NotFoundException when running Roboelectric test

放肆的年华 提交于 2019-11-29 13:44:30
I've just set up Roboelectric 3.2.2 with a new app and I have written my first simple test: @RunWith(RobolectricTestRunner.class) @Config(manifest="src/main/AndroidManifest.xml", packageName="my.pacakge.name.debug") public class MainActivityTest { @Test public void clickButton() { MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class); String text = ((TextView)mainActivity.findViewById(R.id.text_main)).getText().toString(); assertEquals("Should equal Hello World!", "Hello World!", text); } } I've followed all the set up and instructions here and here but I am still getting

How to use findViewById() in robolectric

喜你入骨 提交于 2019-11-29 08:48:09
问题 I simply want to test with robolectric if a certain view is visible in a fragment. My unit test looks like this: ActivityController controller = Robolectric.buildActivity(FragmentActivity.class); FragmentActivity activity = (FragmentActivity) controller.create().start().resume().visible().get(); F fragment = new MyFragment(); activity.getSupportFragmentManager().beginTransaction() .add(fragment, FRAGMENT_TAG).commit(); View view = fragment.getView().findViewById(R.id.my_view); assertEquals

Using multiple res folders with Robolectric

萝らか妹 提交于 2019-11-28 02:17:21
My current Gradle configuration has multiple (Merged) res folders: sourceSets { androidTest { setRoot('src/test') } main { res.srcDirs = [ 'src/main/res/features/registration', 'src/main/res/features/login', 'src/main/res' ] } } But Robolectric allows me to configure a single directory using AndroidManifest: public class RobolectricGradleTestRunner extends RobolectricTestRunner { private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18; public RobolectricGradleTestRunner(Class<?> testClass) throws InitializationError { super(testClass); } @Override protected AndroidManifest