robolectric

Test DatePickerDialog with robolectric

徘徊边缘 提交于 2019-12-03 15:36:58
I'm trying to test date picker behavior with robolectric. @Test public void shouldSetStartedOnDate() { activity.findViewById(R.id.cruise_form_pick_started_on_button).performClick(); DatePickerDialog dialog = (DatePickerDialog) ShadowDatePickerDialog.getLatestDialog(); assertThat(dialog.isShowing(), is(true)); dialog.updateDate(2013, 3, 13); ShadowDialog shadowDialog = Robolectric.shadowOf(dialog); shadowDialog.clickOnText("Done"); assertThat(dialog.isShowing(), is(false)); TextView startedOnText = (TextView) activity.findViewById(R.id.cruise_form_started_on); assertThat(startedOnText.getText()

can jmockit and robolectric coexist?

淺唱寂寞╮ 提交于 2019-12-03 15:25:31
I'm trying to implement a unit test using Robolectric to replace the stubbed methods in android.jar while also using jMockit to mock an Android class (Fragment, in my case). However, I can't seem to get it to work. If I annotate the test class with @RunWith(RobolectricTestRunner.class) , I get: java.lang.IllegalStateException: JMockit wasn't properly initialized; check that jmockit.jar precedes junit.jar in the classpath (if using JUnit; if not, check the documentation) If I use @RunWith(JMockit.class) or no @RunWith , I get "Stub!" exceptions. At the moment, my classpath has things in the

Robolectric + rxJava + retrofit Second call throws java.io.InterruptedIOException

心已入冬 提交于 2019-12-03 14:52:23
I am developing and android app. I am using retrofit (with OkClient) for api requests and Robolectric for testing. My api looks like this: @GET("/v1/book/{bookId}") Observable<Book> getBook(@Path("bookId") int bookId); Just for Robolectric I am forcing api calls to be synchronous. The restAdapter builder looks like this: RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(environment.getServerEndpoint()) .setClient(new OkClient(client)) .setExecutors(new ImmediateExecutor(), null) .setErrorHandler(new ErrorHandler()) .setRequestInterceptor(new RequestInterceptor() { @Override

Android Lollipop Appcompat problems running with Robolectric

五迷三道 提交于 2019-12-03 13:01:55
问题 I'm not able to run Robolectic test when using new Appcompat support library available since Android Lollipop came out. I've followed: https://github.com/robolectric/deckard-gradle https://chris.banes.me/2014/10/17/appcompat-v21/ My current progress is available here: https://github.com/fada21/android-tdd-bootstrap My configuration (distilled) is: android { compileSdkVersion 21 buildToolsVersion "21.0.1" defaultConfig { applicationId "com.fada21.android.bootstrap" minSdkVersion 15

How to turn on robolectric logging

女生的网名这么多〃 提交于 2019-12-03 11:47:54
I need a very simple way to get Robolectric 3.0 to turn on logging. I want to see the output from robolectric, not just my tests. Everything I tried off the web is not working. Where do I stick this? robolectric.logging.enabled = true I tried the following: In a robolectric.properties file in test/java/res In a robolectric.properties file in test/java/resources In a robolectric.properties file in test/res In a robolectric.properties file in test/resources In gradle: afterEvaluate { project.tasks.withType(Test) { systemProperties.put('robolectric.logging.enable', 'true') } } In gradle: tasks

osx maven running tests Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “main”

妖精的绣舞 提交于 2019-12-03 11:29:31
I have been trying to run on mac a ready maven project which works under linux. When calling mvn clean install it runs a portion of the tests and then I am getting the following error: Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main" I have seen many questions about Perm gen error fixed with adding MAVEN_OPTS to environmental variables. Right now I have the following environmental variable on my system: MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=4096m" When calling mvn help:system I can see these options showing up in the

Robolectric unit tests fail after Multidex

对着背影说爱祢 提交于 2019-12-03 08:08:24
问题 So I recently merged my robolectric 3.0 upgrade with our mainline, which had added multidex support to our application. Unfortunately, this had the unfortunate side effect of causing our tests to fail/not run - they'd simply stop after the first failed attempt to install MultiDex, with this stack trace: java.lang.RuntimeException: java.lang.RuntimeException: Multi dex installation failed (/Users/me/Data/Projects/my-android/myapp/. (Is a directory)). at org.robolectric.RobolectricTestRunner$2

Android http testing with Robolectric

丶灬走出姿态 提交于 2019-12-03 06:49:40
I have an Android app where the main part of the app is the APIcalls.java class where I make http requests to get data from server an display the data in the app. I wanted to create unit test for this Java class since it's the most part of the app. Here is the method for getting the data from server: StringBuilder sb = new StringBuilder(); try { httpclient = new DefaultHttpClient(); Httpget httpget = new HttpGet(url); HttpEntity entity = null; try { HttpResponse response = httpclient.execute(httpget); entity = response.getEntity(); } catch (Exception e) { Log.d("Exception", e); } if (entity !=

Mock HttpResponse with Robolectric

亡梦爱人 提交于 2019-12-03 06:01:42
Using Robolectric 2.3-SNAPSHOT, I want to test an object that'll execute a request in the background. In order to isolate it, I'm trying to mock the HttpResponse returned, without success after some hours invested. I've created a project that anyone can clone. Simly run ./gradlew check https://github.com/Maragues/RobolectricDummyProject (git clone https://github.com/Maragues/RobolectricDummyProject.git ) I've tried Robolectric.setDefaultHttpResponse(200, "my_mocked_word"); MockWebServer ( https://code.google.com/p/mockwebserver/ ) But the tests fail because they query the real URL private

ClassCastException: NoClassDefFoundError cannot be cast to RuntimeException

独自空忆成欢 提交于 2019-12-03 05:52:04
I am working on upgrading my codebase to Gradle 2.2 and Android Studio 1.0. I am currently trying to get Robolectric 2.4 working, but I am experiencing a strange issue when I try and run Unit Tests. The issue occurs only after a gradle clean ; running the test suite multiple times will produce passing tests (as expected). When I run the tests after a clean, I get the following error: java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.RuntimeException I have traced the error back to this call: Activity activity = Robolectric.setupActivity(MainActivity.class