lundi 23 avril 2018

Android - Mock method of Application during instrumented test

Assuming my Application class is like following:

import android.app.Application;

public class MyApp extends Application {

    public String example(){
        return "Test";
    }

}

I have some instrumented tests for testing UI. Assuming I have the following test:

public class MyMainActivityTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    @Test
    public void firstTest(){
       onView(withId(R.id.textBt)).perform(click());
       // ...
    }
}

I want to mock example() method inside MyMainActivityTest, let's say that it should return Mock Test instead of Test. How to do it?

Aucun commentaire:

Enregistrer un commentaire