mockito - Robolectric Retrofit test to Android test framework -


i trying write test in android testing framework run on emulator since can't use robolectric in project compatibility reasons.

  1. how switch , use (activityinstrumentationtestcase2, activitytestcase)?

  2. maybe example?

i trying convert test project, , here code

package com.swanson.octodroid.test; import java.util.arraylist; import java.util.list;  import org.junit.before; import org.junit.test; import org.junit.runner.runwith; import org.mockito.argumentcaptor; import org.mockito.captor; import org.mockito.mock; import org.mockito.mockito; import org.mockito.mockitoannotations; import org.robolectric.robolectric; import org.robolectric.shadows.shadowtoast; import org.robolectric.util.activitycontroller;  import retrofit.callback;  import com.swanson.octodroid.github; import com.swanson.octodroid.mainactivity; import com.swanson.octodroid.owner; import com.swanson.octodroid.repository;  import static org.fest.assertions.api.assertions.assertthat;  import static org.fest.assertions.api.android.assertthat;   @runwith(customtestrunner.class) public class mainactivitytest {      private mainactivity activity;      @mock     private github mockapi;      @captor     private argumentcaptor<callback<list<repository>>> cb;      @before     public void setup() {         mockitoannotations.initmocks(this);          activitycontroller<mainactivity> controller = robolectric.buildactivity(mainactivity.class);         activity = controller.get();         activity.setapi(mockapi);          controller.create();     }      @test     public void shouldfilladapterwithreposfromapi() throws exception {         mockito.verify(mockapi).repositories(mockito.anystring(), cb.capture());          list<repository> testrepos = new arraylist<repository>();         testrepos.add(new repository("rails", "ruby", new owner("dhh")));         testrepos.add(new repository("android", "java", new owner("google")));          cb.getvalue().success(testrepos, null);          assertthat(activity.getlistadapter()).hascount(2);     }      @test     public void shouldtoastsadmessageifnorepos() throws exception {         mockito.verify(mockapi).repositories(mockito.anystring(), cb.capture());          list<repository> norepos = new arraylist<repository>();          cb.getvalue().success(norepos, null);          assertthat(shadowtoast.gettextoflatesttoast()).contains("no repos :(");         assertthat(activity.getlistadapter()).isempty();     }      @test     public void shouldtoastifapierror() throws exception {         mockito.verify(mockapi).repositories(mockito.anystring(), cb.capture());          cb.getvalue().failure(null);          assertthat(shadowtoast.gettextoflatesttoast()).contains("failed");     }  } 


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -