How to combine many Spring test annotations in a single annotation?

Ok so I've found some old discussions about this on the JUnit GitHub:

  • https://github.com/junit-team/junit/issues/194
  • https://github.com/junit-team/junit/issues/202

It is some sort of trade-off between readability and DRY-ness.

Allowing some meta-annotations could also slow down tools like IDEs.

I doesn't seem that it's on the way to be implemented any time soon, so for now I will have to keep my two annotations.


Meta-annotations are not the only way of code reuse. We use inheritance instead:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Config.class)
@IntegrationTest
@Sql({"classpath:rollback.sql", "classpath:create-tables.sql"})
@Transactional
public abstract class IntegrationTest {
}

public class FooTest extends IntegrationTest {

}

public class BarTest extends IntegrationTest {

}

Unlike meta-annotations, annotation inheritance from base classes is understood by both Spring and JUnit.