In our project, we have a lot of JUnit 4 tests, and they are executed from Gradle.
Now, we wanted to insert an initializer for the entire "gradle test" execution. The initializer is a class-loading tweak, so it should run just once in the very beginning.
I have looked into some:
- JUnit's
RunListener
RunListener
does not run on Gradle.- https://github.com/gradle/gradle/issues/1330
- Similar with
junit-foundation
- I was trying this, but it didn't work for unsure reasons yet.
- It might be because of its complicated classloading structure.
- Still worth going deeper into it.
- I was trying this, but it didn't work for unsure reasons yet.
- JUnit's
RunWith
- We need to specify all the test class names.
- We already have a lot of test classes.
- And, when we add a new test class, we have to add the test class there, too. We easily forget.
- JUnit 4: Set up things in a test suite before tests are run (like a test's @BeforeClass method, just for a test suite)
- We wanted all the test classed to be looked up automatically (like normal
gradle test
). ClasspathSuite
may help to auto-lookup test classes?- But,
gradle tests --tests="..."
would not work as intended.
- We need to specify all the test class names.
- Static initializer in test classes, to run just once through the entire test run?
- Need to add so many
static {}
blocks in so many existing tests? - Easily to forget, too.
- Need to add so many
Does anyone have any more ideas to solve this? (If we have a way in JUnit 5, we'll consider that.)