@Ignore
public abstract class PlayerActionAbstractTest {
static {
assertTrue(true);
}
private final Supplier<PlayerAction> playerActionSupplier;
private PlayerAction playerAction;
public PlayerActionAbstractTest() {
this.playerActionSupplier = null;
}
protected PlayerActionAbstractTest(final Supplier<PlayerAction> playerActionSupplier) {
this.playerActionSupplier = Objects.requireNonNull(playerActionSupplier, "playerActionSupplier");
}
@Before
privatefinal public void beforebeforePlayerActionAbstractTest() {
playerAction = playerActionSupplier.get();
}
@Test(expected = NullPointerException.class)
public void testIsActionAllowedNullPlayer() {
playerAction.isActionAllowed(null);
}
@Test(expected = NullPointerException.class)
public void testPerformActionNullPlayer() {
playerAction.performAction(null);
}
}
The pros are that the instance only needs to be passed in once and most importantly that you must pass it in or you will get a compiler error. Another pro is that the list of classes to be tested is not defined in the abstract testclass itself.
Last update, appereantly the latest change was showing weird behaviours when executing unit tests on my whole project, rather than a single file. I have changed the following:
- Changed signature in
PlayerActionAbstractTest
fromprivate void before()
tofinal public void beforePlayerActionAbstractTest()
, as the@Before
method needs to bepublic
and in case inheriting multiple times is possible,beforeSuper()
would clash. - Changed the
public PlayerActionAbstractTest(final Supplier<PlayerAction> playerActionSupplier)
constructor toprotected PlayerActionAbstractTest(final Supplier<PlayerAction> playerActionSupplier)
, to fix that a test class must only have one public zero-args constructor. - Added
public PlayerActionAbstractTest()
to make it have one public zero-args constructor. - Added
@Ignore
to ensure that this abstract class itself isn't being tested.