The subsequent suggestion lets you test abstract classes without building a "real" subclass - the Mock is the subclass.
use Mockito.mock(My.class, Mockito.CALLS_REAL_METHODS), then mock any abstract rules that are requested.
Citation:
public abstract class My {
public Result methodUnderTest() { ... }
protected abstract void methodIDontCareAbout();
}
public class MyTest {
@Test
public void shouldFailOnNullIdentifiers() {
My my = Mockito.mock(My.class, Mockito.CALLS_REAL_METHODS);
Assert.assertSomething(my.methodUnderTest());
}
}
The advantage of this resolution is that you do not have to implement the abstract methods, as long as they are nevermore invoked.
In my trustworthy viewpoint, this is neater than using a spy, since a spy requires an example, which indicates you have to create an instantiable subclass of your abstract class.