robolectric

Unable to execute dex: Multiple dex files define Lorg/apache/maven/artifact/Artifact

情到浓时终转凉″ 提交于 2019-12-24 13:29:53
问题 I have an Android project with Robolectric. My application related classes are placed in src/main/java and test related classes in src/test/java . I have these test dependencies in my pom.xml <dependency> <groupId>org.robolectric</groupId> <artifactId>robolectric</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> When building and deploying from console with mvn package android:deploy everything

Robolectric TypedArray getString() returns null or empty string

最后都变了- 提交于 2019-12-24 12:58:37
问题 I'm using Robolectric to test an activity that inflates a custom view, but when fetching values from the TypedArray everything comes back null or an empty string. What needs to be done in order to get the correct value from the typed array? 回答1: Robolectric doesn't re-implement the entire Android standard library. Here is a link to the TypeArray Shadow class: https://github.com/pivotal/robolectric/blob/master/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTypedArray.java It seems to

Mock native method with a Robolectric Custom shadow class

假装没事ソ 提交于 2019-12-24 12:04:04
问题 I have a class with a regular method and a native method that I'd like to mock: public class MyClass { public int regularMethod() { ... } public void native myNativeMethod(); } I am using Robolectric to test my app, and I am trying to figure out a way to mock these methods using a custom shadow class. Here is my shadow class: @Implements(MyClass.class) public class MyShadowClass { @Implementation public int regularMethod { return 0; } @Implementation public void nativeMethod { ... } } Here is

Robolectric not handling getApplicationContext() correctly - NPE

拥有回忆 提交于 2019-12-24 09:36:44
问题 I've been running some tests on an android application using Robolectric and it's been working well until now. My application passes the result of getApplicationContext() to a constructor, but Robolectric should be ensuring the value of this is not null as I am using the BuildActivity() method. The error is in some configuration of my test environment, or a bug in Robolectric. The result is a NullPointerException in the constructor of Toast. My environment: com.android.tools.build:gradle:3.0

Writing Android acceptance tests with robolectric: how could it be done?

梦想与她 提交于 2019-12-24 05:37:22
问题 Can Android acceptance tests be written using Robolectric? It seems to be classed only as a unit-testing framework. Why can it not be classed as acceptance or "end-to-end" testing framework? (Can it be adapted for that purpose?) 回答1: I think this may be a bit subjective, but I feel it's answerable, so here's my take on it. Is it an e2e testing framework? It cannot be "end-to-end" because the application doesn't actually run on a device, the dependencies may be mocked out, network is usually

java.lang.NoSuchMethodError: java.lang.System.arraycopy using XmlPullParser with Robolectric

Deadly 提交于 2019-12-24 03:51:42
问题 I am trying to test my Android app in Android-Studio with Robolectric. One of my unit tests makes use of XmlPullParser : InputStream in = new FileInputStream(new File("somefile.xml")); XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); parser.nextTag(); while(parser.next()!=XmlPullParser.END_DOCUMENT){ // ... } Here is what happens when I run the test: java.lang.NoSuchMethodError: java.lang.System

Robolectric test cases of flavor A passes while flavor B fails

吃可爱长大的小学妹 提交于 2019-12-23 17:26:23
问题 My app contains two flavors of A and B. When I run ./gradlew app:test all tests of flavor A passes while flavor B fails. I also have two build types of debug and release . My architecture is like this: \my-project ---- \app -------- \src ------------ \debug ------------ \flavor_A ------------ \main ------------ \flavor_B ------------ \test ---------------- \java -------------------- \ com.my.main.package ------------------------ \ My_test_classes.java -------------------- \ TestApplication

Is it possible to test an Abstract activity with Robolectric

十年热恋 提交于 2019-12-23 12:43:27
问题 I use abstract activity classes in my code to well, abstract away some features from the activity classes. I'm trying to test the abstract activity classes using Robolectric and the gradle-android-test-plugin using subclasses that extend the abstract class. I can't seem to get it to work though. Does anyone have any experience in this area and is it even possible ? Basic structure is : @RunWith(RobolectricGradleTestRunner.class) public class AbstractActivityTest { private ActivityTest

Robolectric test needs to wait for something on a thread

家住魔仙堡 提交于 2019-12-23 12:05:37
问题 My class does this: public void doThing() { Doer doer = new Doer(); Thread thread = new Thread(doer); thread.start(); } The 'Doer' class is an inner class: private class Doer implements Runnable { public void run() { Intent myIntent = new Intent(mContext, MyService.class); mContext.startService(myIntent); ...Some more stuff... } This works fine. I need to test this using Robolectric. Naturally doThing() returns immediately and I need to give the thread a chance to run before I do

Android Instrumentation test java.lang.UnsatisfiedLinkError on using AndroidJunitRunner and AndroidJUnit4

喜欢而已 提交于 2019-12-23 10:28:17
问题 I am using robolectric in our unit tests. Recently in our project, we are adding a new dependency from zendesk. repositories { maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' } } compile group: 'com.zendesk', name: 'sdk', version: '1.3.0.1' Now we have not even referenced any class from this library and we are getting exceptions in our robolectric unit tests just by adding this dependency. I thought the problem is in our project, but its also occurring on a sample robolectric