mockito test abstract class method

    When testing a method of an abstract class, because the called object cannot be directly new, we can use Mockito.mock(My.class, Mockito.CALLS_REAL_METHODS), and then we can call the tested method.

    private void givenAbstractStoryURLHandler() {
        abstractStoryURLHandler = Mockito.mock(AbstractStoryURLHandler.class, Mockito.CALLS_REAL_METHODS);
    }

    private void whenGetAncestors() throws Exception{
        createMocks();
        abstractStoryURLHandler.getAncestors(mockAssetCategory);
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326470025&siteId=291194637