dimanche 28 janvier 2018

Mockito verify only passes with AVD running

I want to test a MVP-Pattern. So i have a Presenter class, which shall invoke the View methods when certain buttons are clicked. Now I want to verify, that the Presenter really invokes the Method, so I wrote these tests:

Test Class:

@Mock
private MainContract.View view;

private MainPresenter presenter;

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    presenter = new MainPresenter(view);
}

@Test
public void handleScanButtonClicked() {
    presenter.handleScanButtonClicked();
    verify(view).showScanScreen();
}

@Test
public void handleBackButtonClicked() {
    presenter.handleBackButtonClicked();
    verify(view).showMainScreen();
}

Presenter Class:

private final MainContract.View view;

public MainPresenter(MainContract.View view) {
    this.view = view;
}

@Override
public void handleScanButtonClicked() {
    view.showScanScreen();
}

@Override
public void handleBackButtonClicked() {
    view.showMainScreen();

}

My Testing Dependencies in build.gradle:

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.10.19'

When I now run the tests without an AVD running, they will fail. I want to run those tests on my local machine only, and there should be no interactions with Android specificly, right? But to let the tests pass, I need to start an AVD, and build + deploy the APK.

Why is this, and how can I run those kind of tests properly on my local machine?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire