robolectric

Robolectric InflateException when using v7 support library AlertDialog

回眸只為那壹抹淺笑 提交于 2019-12-23 09:48:40
问题 Using a normal android.app.AlertDialog works with ShadowAlertDialog.getLatestAlertDialog() , but if you use a support library android.support.v7.app.AlertDialog , then this exception happens: android.view.InflateException: XML file app/build/intermediates/res/qa/debug/layout/abc_alert_dialog_material.xml line #-1 (sorry, not yet implemented): Error inflating class android.support.v7.internal.widget.DialogTitle at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) at

Google Analytics - NullPointerException in Test

陌路散爱 提交于 2019-12-23 09:31:59
问题 I'm getting the following NPE in a Robolectric test on a Travis build-server, and I'm having trouble pinpointing why. I'm unable to reproduce this issue locally. Anybody know what causes onServiceConnected to be called? That might help me pinpoint the issue. From what I can tell this is a Google Play Services - Google Analytics issue. java.lang.NullPointerException at com.google.android.gms.analytics.c$a.onServiceConnected(Unknown Source) at com.google.android.gms.analytics.c$a

Add resolve info to Robolectric package manager

穿精又带淫゛_ 提交于 2019-12-23 09:14:49
问题 This SO question is very similar to what I want to do: How can I shadow the PackageManager with Robolectric However, all the answers rely on ShadowApplication.setPackageManager(). In 2.2, this method no longer seems to exist: http://robolectric.org/javadoc/org/robolectric/shadows/ShadowApplication.html I attempted to just grab the package manager and add a resolve info: RobolectricPackageManager packageManager = (RobolectricPackageManager) Robolectric.application.getPackageManager(); Intent

How to test an IntentService with Robolectric?

自古美人都是妖i 提交于 2019-12-23 07:20:35
问题 I'm trying to test the onHandleIntent() method of an IntentService using Robolectric . I'm starting the service with: Activity activity = new Activity(); Intent intent = new Intent(activity, MyService.class); activity.startService(intent); ShadowActivity shadowActivity = Robolectric.shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedService(); assertNotNull(startedIntent); seems like startedIntent is not null, but onHandleIntent() doesn't seem to be called. how should I

Robolectric: running multiple tests fails

冷暖自知 提交于 2019-12-23 06:58:36
问题 I am trying to run multiple tests with Robolectric 3.0 + Gradle using SQLite (OpenHelper) as database. Running each single tests works fine, but starting the whole test suite always results in RuntimeException in the 2nd test. This is my test dummy, which does not work. @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21) public class Dummy { @Before public void setUp() throws Exception { // setup activity ... } @Test public void testA() throws

Robolectric 3.0 Nullpointer on DefaultPackageManager.getActivityInfo()

徘徊边缘 提交于 2019-12-23 03:05:21
问题 I try to create a Robolectric test (3.0-rc02) for the following Activity: public class NotificationActivity extends ActionBarActivity { private NotificationFragment fragment; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); } } The test is looking like this: @Config(manifest = IConfig.MANIFEST_PATH, emulateSdk = IConfig.SDK_VERSION, reportSdk = IConfig.SDK_VERSION) @RunWith

Unable to get log.d or output Robolectrict + gradle

雨燕双飞 提交于 2019-12-22 12:50:36
问题 Has anyone being able to output System.out or Log.d traces from robolectric test to gradle console. I am using Robolectric Gradle test plugin I use the console to run my test since it is more painful to try to run it in AS, anyway I was trying to output the my test classes but unable to get them I've try from ShadowLog.stream=stdout to robolectric.logging in gradle file, and nothing . Has anyone able to achieve this. Thanks. 回答1: If you run test in Android Studio terminal you can do that.

Robolectric 3.0 java.lang.NoSuchMethodException on create activity

此生再无相见时 提交于 2019-12-22 08:11:44
问题 I was excited to hear that android studio had made some updates to make unit testing simple to do in android studio so I have been trying to set up roboelectric but I cant get past this error that occurs during the following method. MainActivity = Robolectric.buildActivity(MainActivity.class).create().get(); with the following stacktrace Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: java.lang.Object.attach(android.content.Context, android.app.ActivityThread, android

Robolectric: NullPointerException in setupActivity()

主宰稳场 提交于 2019-12-22 05:23:44
问题 I'm trying to use Robolectric for testing my activities, but I'm always getting a NPE, when trying to setup the Activity with Robolectric. I have followed the guide from the robolectric.org website. Here is my code: @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP, manifest = "src/main/AndroidManifest.xml") @RunWith(RobolectricTestRunner.class) @Ignore public class MainActivityUnitTest { private MainActivity activity; @Before public void setup() { activity =

How can I use Active Android with an in memory database for unit tests using Robolectric?

非 Y 不嫁゛ 提交于 2019-12-22 04:40:06
问题 As the title says. I am aware that there is a limited in memory database provided in robolectric. Is there any way to use this with Active Android? Under the default configuration, it appears that the database is cleared after all the tests are run, but not for each test. 回答1: I use greenDao - but the principle is the same. My Application class initialises my DB (the DB has a name). For my tests I subclass Application (which allows Robolectric to call this version instead) and override the