I want to write a test for a small database-like application. This application uses queries and a query should return the correct result. This is easily implemented in JUnit 5, something like
@BeforeEach
void before() {
database = prepareDatabase();
}
@Test
void testQuery1() {
assertThat(database.query("query1")).isEqualTo("result1");
}
@Test
void testQuery2() {
assertThat(database.query("query2")).isEqualTo("result2");
}
....
Now I want to add optimization switches (e.g. a query optimizer or database indices). The query should return the same results regardless of the running optimization switch (optimizations should only change efficiency not results).
For the test this means that I want to run the same methods for slightly other implementations of prepareDatabase()
(e.g. one with optimizer, one with index, one with nothing).
I did not yet find a proper extension for this. I thought of duplicating the whole class for each optimization setting or providing the methods from a shared parent class. Yet this does not feel like the JUnit 5 way of doing this task. Maybe someone could point me to a feature that could help me with this problem?