NPE when calling MockitoAnnotations.initMocks() in AndroidTestCase

前端 未结 4 1777
耶瑟儿~
耶瑟儿~ 2021-01-04 09:04

Trying to use mockito in my AndroidTestCase. I added the dependencies to the build.gradle:

final DEXMAKER_VERSION = \'1.2\'

dependencies {
    // ...
    an         


        
4条回答
  •  孤街浪徒
    2021-01-04 09:57

    For me the solution was to use the Method Mockito.mock() for each Mocking Object instead of using MockitoAnnotations.initMocks(this);

    So for example:

    public class HomePresenterTest {
        private Repository repository;
        private HomePresenter presenter;
    
        @Before
        public void before() {
            repository = mock(Respository.class);
            presenter = new HomePresenter(repository);
        }
    
        //Your tests
    }
    

提交回复
热议问题