How to avoid inheritance in JUnit test cases?

Viewed 15608

I have a number of test cases in JUnit. All of them need the same code to be executed in their @BeforeClass static method. It's a code duplication and I'm trying to get rid of it. A dirty way of doing this is by inheritance. Are there any other mechanisms in JUnit, that may help?

PS. I wrote this blog post about this very subject: http://www.yegor256.com/2015/05/25/unit-test-scaffolding.html

8 Answers
Related