robolectric

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

Robolectric Unit Test failing with Android Studio 2.3 updates

喜你入骨 提交于 2019-11-29 13:24:14
问题 All my Unit Test started throwing this error: No such manifest file: build\intermediates\bundles\debug\AndroidManifest.xml java.lang.NullPointerException at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:375) at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:117) at android.content.res.AssetManager.getResourceValue(AssetManager.java) at android.content.res.Resources.getValue(Resources.java:1347) at android.support.v7

Testing custom Views with Robolectric

牧云@^-^@ 提交于 2019-11-29 10:29:51
问题 I'm trying to run unit tests with Robolectric 2.1.1 and I cannot get it to inflate custom layouts (e.g. ViewPagerIndicator classes). Suppose this is my layout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="test" android:id="@+id/test_test"/> <com.viewpagerindicator

Does Robolectric support API level?

一世执手 提交于 2019-11-29 10:29:49
问题 I have some Test which I would like to run with Robolectric, I use the 2.3-SNAPSHOT as my APP uses the ActionbarCompat i needed to use 2.3-SNAPSHOT Version as Robolectric could not find the AppCompat Themes before. So I setup the Classpath in Eclipse and I end up with this: java.lang.UnsupportedOperationException: Robolectric does not support API level 9, sorry! at org.robolectric.SdkConfig.<init>(SdkConfig.java:24) at org.robolectric.RobolectricTestRunner.pickSdkVersion(RobolectricTestRunner

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

Robolectric 2.1 and Eclipse

﹥>﹥吖頭↗ 提交于 2019-11-29 07:24:20
Robolectric seems to be a very interessting alternative android application testing, but I can't properly integrate it with my Eclipse enviroment. Using the latest robolectric version 2.1 and android sdk 8, I follow the Eclipse setup steps described on the robolectric website but with no luck. When I run my newly created run configuration, the test is stopped the following error. I don't know exactly why my pakpak .R class cant be found and what is the ro.build.date.utc? a symptom or the problem? WARNING: no system properties value for ro.build.date.utc java.lang.RuntimeException: java.lang

In Robolectric, how do I get around DrawerLayout must be measured with MeasureSpec.EXACTLY error?

坚强是说给别人听的谎言 提交于 2019-11-29 06:07:15
问题 I'm trying to add a DrawerLayout to my application for navigation, and I'm testing my application with Robolectric (I've seen this problem both with Robolectric 2.1.1 and 2.1-SNAPSHOT - 2.2-20130712.161723-17) I'm using the following xml for the base of my drawer layout. I encounter the error in Robolectric when I have the andioid:layout_width or android:layout_height set to be "match_parent" on the Drawer Layout. <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout

How can I shadow the PackageManager with Robolectric

久未见 提交于 2019-11-29 05:58:04
My Android application has a simple method to fire off an intent to display a URL. protected void launchBrowser(int id) { Uri uri = Uri.parse( getString( id ) ); Intent intent = new Intent( ACTION_VIEW, uri); PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); if (activities.size() > 0) { startActivity(intent); } else { Toast.makeText(getApplicationContext(), "ERROR - no application to display a web page", Toast.LENGTH_SHORT).show(); } } I'm using Robolectric for unit testing but I'm having trouble verifying this

Gradle + Robolectric: Where do I put the file org.robolectric.Config.properties?

。_饼干妹妹 提交于 2019-11-29 03:04:36
I'm trying to setup a test using Robolectric to click on a menu button in this repository . Basic Robolectric tests will run, but I'm not able to run any project-specific test using resources because it says it can't find my AndroidManifest.xml. After running ../gradlew clean check , here's the standard output from the Robolectric html file: WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class with @Config(manifest=Config.NONE). I found these instructions which indicate I should create an org

Robolectric: Resources$NotFoundException: String resource ID with Android Gradle Plugin 3

风流意气都作罢 提交于 2019-11-29 02:49:05
Android Studio 3.0 Beta2 classpath 'com.android.tools.build:gradle:3.0.0-beta3' testCompile 'org.robolectric:robolectric:3.4.2' Test class that I am using that fails to run: @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricTestRunner.class) public class RecipeAdapterTest { private MainActivity activity; @Before public void setup() { activity = Robolectric.setupActivity(MainActivity.class); /* Also tried this same Error activity = Robolectric.buildActivity(MainActivity) .create() .resume() .get(); */ } @Test public void testActivityShouldNotBeNull()