robolectric

Robolectric @Config path value for manifest

不想你离开。 提交于 2019-12-06 03:02:49
问题 I am trying to run robolectric unit test but I am getting error as AndroidManifest.xml not found on path. Can anyone give me an example path of @Config manifest value. Is it relative path or absolute one? Thanks in advance 回答1: If you are using maven to run your tests you can set as follows: @Config(manifest = "../app/AndroidManifest.xml") @RunWith(RobolectricTestRunner.class) public class SomeTestCase { ... } Please note that if you are using Android Studio/Intellij and want to run your

How to get Spannable and its color from TextView to write a unit test

Deadly 提交于 2019-12-06 02:19:47
问题 private void createStringEndingInRedColor(TextView tv, String word1, String word2) { Spannable word = new SpannableString(word1); tv.setText(word); Spannable wordTwo = new SpannableString(word2); wordTwo.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(Color.RED)), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.append(wordTwo); } I'm trying to write a unit test (using Robolectric) for the TextView tv to ensure that wordTwo is Color.RED. However, I only have a

Spurious Test Failures using Picasso and Robolectric

故事扮演 提交于 2019-12-06 01:39:32
I just upgraded to Robolectric 2.1.1 and integrated Picasso today. I now have two test cases that fail randomly (one of these fragments doesn't even use Picasso). If I keep running the tests, everything usually ends up passing (might take a few tries). Test @Before public void setUp() throws Exception { detailActivity = Robolectric.buildActivity( ActivityUnderTest.class ) .withIntent( createIntent() ) .create() .start() .resume() .get(); // Note: The other test case doesn't use the fancy withIntent() doohickey } public static Intent createIntent() { Bundle bundle = DetailFragment.createBundle(

Robolectric 3.0 java.lang.NoSuchMethodException on create activity

无人久伴 提交于 2019-12-05 17:56:19
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.app.Instrumentation, android.os.IBinder, int, android.app.Application, android.content.Intent, android

Assert ImageView was loaded with specific drawable resource ID

狂风中的少年 提交于 2019-12-05 13:02:39
问题 I'm writing a Robolectric unit test and I need to make an assertion that an ImageView had setImageResource(int) called on it with a certain resource ID. I'm using fest-android for assertions but it doesn't appear to contain this assertion. I also tried to get the ShadowImageView from Robolectric for the ImageView because I know it used to give you access to this, but it's now gone. Lastly, I tried to call setImageDrawable in my code instead of setImageResource, then in my test assert like

How to load .so when using Robolectric?

半世苍凉 提交于 2019-12-05 10:06:18
W/Environment: EXTERNAL_STORAGE undefined; falling back to default java.lang.UnsatisfiedLinkError: com.autonavi.amap.mapcore.MapCore.nativeNewInstance(Ljava/lang/String;)J at com.autonavi.amap.mapcore.MapCore.nativeNewInstance(Native Method) at com.autonavi.amap.mapcore.MapCore.<init>(MapCore.java:62) at com.amap.api.mapcore.AMapDelegateImpGLSurfaceView.<init>(AMapDelegateImpGLSurfaceView.java:356) at com.amap.api.mapcore.AMapDelegateImpGLSurfaceView.<init>(AMapDelegateImpGLSurfaceView.java:318) at com.amap.api.mapcore.ak.a(MapFragmentDelegateImp.java:123) at com.amap.api.maps.MapView.onCreate

Robolectric: NullPointerException in setupActivity()

流过昼夜 提交于 2019-12-05 07:29:04
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 = Robolectric.setupActivity(MainActivity.class); } @Test public void dummyTest() { assertTrue(true); } } Some

Android build tools 1.1.0, unit test folder?

偶尔善良 提交于 2019-12-05 05:29:52
I recently installed the latest tools from google to my android project: buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "com.xxx" minSdkVersion 10 targetSdkVersion 21 versionCode 200 versionName "2.0" testInstrumentationRunner "android.support

Is anyone out there using Robolectric without Maven on IntelliJ? [closed]

断了今生、忘了曾经 提交于 2019-12-05 04:23:42
Closed . This question is opinion-based . It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 6 years ago . All the examples of using Robolectric I can find seem to be Maven based. Is anyone not using Maven? If so I'd really like to understand your IntelliJ project setup. Having read this post android-unit-test-approaches it seems sensible to have a tiered approach to unit testig android projects with a combination of pure junit, robolectric & android test framework tests. If

Robolectric, Problems with clicking list items

假装没事ソ 提交于 2019-12-05 03:59:21
I have been struggling with this problem a bit, and I think I am not getting something fundamental about Robolectric. Usually some google searches can help me get to the bottom of this type of problem, but between that and looking at the sample code I am not finding anything of use. I am trying to emulate a click on a list view item and check that an activity is launched after the click. I keep getting back that the current activity I am testing is the resulting activity. I tried removing all of the list item clicking code and checking the resulting activity, and this came back as the