robolectric

Android: Robolectric does not support API level 1

独自空忆成欢 提交于 2019-11-29 00:48:27
问题 This is my basic test class: @RunWith(RobolectricTestRunner.class) public class MainActivityTest { @Before public void setup() { //do whatever is necessary before every test } @Test public void testActivityFound() { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); Assert.assertNotNull(activity); } } When I execute my test under Android Studio, with the Terminal window, I have this error: java.lang.UnsupportedOperationException: Robolectric does not support API

Robolectric says “AndroidManifest.xml not found”

和自甴很熟 提交于 2019-11-29 00:19:11
问题 While trying to get Robolectric RC3 to work in Android Studio, I get Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml at org.robolectric.manifest.AndroidManifest.validate(AndroidManifest.java:120) at org.robolectric.manifest.AndroidManifest.getResourcePath(AndroidManifest.java:469) at org.robolectric.manifest.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java

Jvm options in android when run gradlew test

纵饮孤独 提交于 2019-11-28 23:33:39
I have a project that using Robolectric for unit test purpose. This project uses Robolectric 3.0 and need to add -ea and -noverify options in Virtual Machine options. In Android Studio, I created new JUnit configuration in Run > Edit Configurations... and then set VM Options to -ea -noverify . With this way I success to run my unit test. This is image about my configure, view Here However, for continuous deployment, I need run unit test with command line. So I use ./gradlew test to run unit test. I also add org.gradle.jvmargs=-ea -noverify to gradle.properties file. Unfortunately, it doesn't

How do I know if my app is running with Robolectric?

安稳与你 提交于 2019-11-28 11:58:40
I have an android app that uses ORMLite/SQLite and I use Robolectric in conjunction with JUnit 4 to allow me to run unit tests in Android Studio and on a Jenkins build server. Typically I would setup test data in my tests, in the setup, and then run my test scenarios against it but when I tried to do this I started getting issues and exceptions which seemed to be related to files being locked or something and that seems to be a problem others have had... so what I have done up until now is use the create database method in my database helper to create some dummy data which the tests expect to

Using PowerMock and Robolectric - IncompatibleClassChangeError

假如想象 提交于 2019-11-28 10:51:35
I'm trying to use PowerMockito to mock some static methods in Android Robolectric tests. I'm using JUnit 4.8.2, Robolectric 2.2, Mockito 1.9.5, and PowerMock 1.9.5 as directed here . As I have to use the RoboElectricTestRunner , I'm attempting to use the PowerMockRule to bootstrap PowerMock. However I'm getting an unfortunate java.lang.IncompatibleClassChangeError when the test with PowerMock runs. java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun

Is it possible to do real http requests with robolectric

霸气de小男生 提交于 2019-11-28 08:35:37
The issue I have with robolectric is that it doesn't make real HttpRequests. Could I replace the HttpClient implementation of robolectric using a real one actually making the calls to my local test server? Jan Berkel submitted a pull request to Robolectric that was merged into master on March 8th. You can now call Robolectric.getFakeHttpLayer().interceptHttpRequests(false); in the beginning of your test to bypass the mocked http layer in Robolectric. You can download the jar directly from Sonatype to include in your Eclipse Android project. If you are using Maven and 1.1 has not yet been

How does exactly custom Shadow objects work in Robolectric?

旧巷老猫 提交于 2019-11-28 08:29:25
If I write a custom Shadow for my Activity, and registering it with RobolectricTestRunner, will the framework intercept the Activity with my custom Shadow whenever it's started? Thanks. The short answer is no. Robolectric is selective about what classes it intercepts and instruments. At the time of this writing, the only classes that will be instrumented must have a fully qualified classname match one of these selectors: android.* com.google.android.maps.* org.apache.http.impl.client.DefaultRequestDirector The whole reason for Robolectric's existence is that the classes provided in the Android

Android project with Robolectric and Gradle (Android studio)

心不动则不痛 提交于 2019-11-28 06:54:05
I'm trying to use Robolectric in a project build with gradle inside the new Ide for android: Android studio, but I'm facing a strange problem, I've correctly imported all the libraries and created the "test" folder inside "src", the fact is that whenever I run the tests the ide keep saying "Class not found: "com.example.myandroidproject.test" what I'm doing wrong? i need to change something in the gradle.build? here's my directory structure: This is unlikely to work out of the box as src/test isn't used automatically. You'd need to create a test task automatically that compiles this source

How can we access context of an application in Robolectric?

落花浮王杯 提交于 2019-11-28 06:39:39
Actually, I need to get a response of an API call, for that I required Context . Update. Just use for version 1.x and 2.x: Robolectric.application; And for version 3.x: RuntimeEnvironment.application; You can use RuntimeEnvironment.application Use this: Robolectric.application John Add testImplementation "androidx.test:core-ktx:${deps.testrunner}" And use: private val app = ApplicationProvider.getApplicationContext() To get application context you must do the following: annotate @RunWith(RobolectricTestRunner.class) RuntimeEnvironment.application.getApplicationContext() For the latest

How to debug when running Robolectric tests in Android Studio?

浪子不回头ぞ 提交于 2019-11-28 05:42:33
I need to run debug while my tests execution in Android Studio + Robolectric. Each time I try to run them by selecting debug for the test task from Gradle tasks I get the error message: Error running package_name:app_name [test]: Unable to open debugger port : java.net.SocketException "Socket closed" Any ideas? Eugene I found the reason of the error. To make it run you need to uncheck the "Use in-process build" option in Compiler -> Gradle settings of Android Studio. I was getting this error on linux, and the problem was that the another previous process has taken the port and hung. So, the