I am writing 3 different class tests: HardSudoku, VeryHardSudoku and Sudoku
The HardSudoku and VeryHardSudoku classes extend the Sudoku class
So I would have liked to write these three tests in such a way as to respect the DRY principle, so for that, I think that the best solution is to use genericity within the tests.
Here is how I wanted to proceed:
Tests :
SudokuTest
class SudokuTest<T extends Sudoku> {
@Test
void test_solve_dontThrowError() {
T sudoku = new T();
assertAll(() -> sudoku.solve());
}
@Test
void test_solve_returnValidSolution() {
T sudoku = new T();
sudoku.solve();
assertTrue(SolutionChecker.isValid(sudoku.getGridSolution()));
}
}
HardSudokuTest
public class HardSudokuTest extends SudokuTest<HardSudoku> {
}
VeryHardSudokuTest
public class HardSudokuTest extends SudokuTest<VeryHardSudoku> {
}
Question
The line in the SudokuClass test class :
T sudoku = new T();
Is not valid, so I wanted to ask you how to write these 3 tests in a way that respects the DRY principle? Is it possible to use genericity?
Aucun commentaire:
Enregistrer un commentaire