java - Execute Junit tests on classes in Android Studio without initialising mobile device / emulator -


is there way execute test in android studio specific class without mobile device being used testing environment? tests execute on development machine instead. classes in question not contain android specific code.

this common problem android development , 1 has been solved robolectric. allows tests run on jvm , can therefore ran within android studio. example below taken website.

@runwith(robolectrictestrunner.class) public class myactivitytest {    @test   public void clickingbutton_shouldchangeresultsviewtext() throws exception {     myactivity activity = robolectric.setupactivity(myactivity.class);      button button = (button) activity.findviewbyid(r.id.button);     textview results = (textview) activity.findviewbyid(r.id.results);      button.performclick();     assertthat(results.gettext().tostring()).isequalto("robolectric rocks!");   } } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -