robolectric

Manifest and setup issues getting Robolectric working with Android Studio 1.1.0

感情迁移 提交于 2019-12-19 17:42:52
问题 I am trying to get Robolectric tests up and working in our current project, and not having a lot of luck. My preference would be to get these to run within Android Studio 1.1.0+. This is my project structure: and here is my test: import android.widget.Button; import com.mycompany.android.app.R; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation

Custom Layout Inflation with Fragments in Robolectric not working

旧街凉风 提交于 2019-12-19 06:47:23
问题 When inflating a layout in a Fragment, with the LayoutInflater, i am getting this exception: ./res/layout/locations_list.xml line #-1 (sorry, not yet implemented): Error inflating class com.costum.android.widget.LoadMoreListView I figured out that this is happening when inflating a custom layout in @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.locations_list, container, false); } Edit This is the

Custom Layout Inflation with Fragments in Robolectric not working

时间秒杀一切 提交于 2019-12-19 06:46:14
问题 When inflating a layout in a Fragment, with the LayoutInflater, i am getting this exception: ./res/layout/locations_list.xml line #-1 (sorry, not yet implemented): Error inflating class com.costum.android.widget.LoadMoreListView I figured out that this is happening when inflating a custom layout in @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.locations_list, container, false); } Edit This is the

How to specify classpath ordering in Gradle

ⅰ亾dé卋堺 提交于 2019-12-19 05:17:20
问题 I need to control the ordering of jars in the testRuntime configuration. I must make sure that robolectric-x.x.jar comes before android.jar, or else I get the dreaded RuntimeException("Stub!"). How do I do that? 回答1: Here is my complete build.gradle for running Robolectric tests against my Android app, which uses RoboGuice: apply plugin: 'java' androidJar = new File(System.getenv('ANDROID_HOME'), '/platforms/android-7/android.jar') configurations { robo } dependencies { robo('com.pivotallabs

getSystemService in Robolectric returns object with null Context

ぃ、小莉子 提交于 2019-12-19 03:31:14
问题 In my activity's onCreate I have: AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); When testing the activity with Robolectric I create it with ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class); MainActivity activity = controller.attach().create().get(); The AudioManager is then created but with mContext = null which leads to a NullPointerException when calling registerMediaButtonEventReceiver on it because that

Using assets in robolectric tests

怎甘沉沦 提交于 2019-12-18 18:58:12
问题 In my robolectric tests I am trying to read a file. Since this file contains just the test data I have put it in assets of the tests. The directory structure looks like this. src/main/assets/prod_data_file src/test/assets/test_data_file However when I try to read the file by getShadowApplication().getAssets().open(MY_FILE_PATH) it gives me FileNotFoundException . Does anybody know how to fix this? 回答1: Since my tests are just reading these files and returning file data as a String I was able

Robolectric tanks on Application objects that load JNI libraries. Can I get a workaround?

。_饼干妹妹 提交于 2019-12-18 15:34:35
问题 The Application object for my Android app loads a JNI library, and Robolectric doesn't seem to like that. When I go to run my tests Robolectric craps out and I get this stack trace: java.lang.UnsatisfiedLinkError: no cperryinc-jni in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1045) at com.cperryinc.application.MoolaApplication.(MoolaApplication.java:24) at java

Robolectric tanks on Application objects that load JNI libraries. Can I get a workaround?

雨燕双飞 提交于 2019-12-18 15:33:27
问题 The Application object for my Android app loads a JNI library, and Robolectric doesn't seem to like that. When I go to run my tests Robolectric craps out and I get this stack trace: java.lang.UnsatisfiedLinkError: no cperryinc-jni in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1045) at com.cperryinc.application.MoolaApplication.(MoolaApplication.java:24) at java

How do I create a shadow class to work around crashes related to custom attributes when testing an Android app with Robolectric?

梦想的初衷 提交于 2019-12-18 15:17:17
问题 I'm integrating a custom widget into my project. It uses custom attributes and is crashing Robolectric. From what I gather, custom attributes aren't supported yet. Note: the constructor is "hostile" because it throws exceptions on construction, but I've commented them out for now. Crash Log java.lang.RuntimeException: error inflating layout/main at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:106) at com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader

junit testing with gradle for an android project

隐身守侯 提交于 2019-12-18 10:50:56
问题 I am trying to get tests ( junit and robolectric ) working in an Android project but am totally stuck. My main problem is that all testing I found with gradle somehow pull in the java plugin and then I get this error: The 'java' plugin has been applied, but it is not compatible with the Android plugins. The only way out I see at the moment is to split into test and app project - but I would like to avoid that. Any examples/hints would be highly appreciated! In the official documentation there