Currently, there’s no native Gradle facility that allows you to attach a JUnit 4 RunListener to your tests. There’s an open request to add this feature, but this has yet to be implemented. Until this feature is delivered, you can attach RunListener classes to your JUnit 4 tests with JUnit Foundation.
The JUnit Foundation library enables you to declare your listeners in a service provider configuration file, which are then attached automatically - regardless of execution environment. Details can be found here.
With this configuration, the listener implemented by MyRunListener will be automatically attached to the RunNotifier supplied to the run() method of JUnit runners. This feature eliminates behavioral differences between the various test execution environments like Maven, Gradle, and native IDE test runners.
Development on JUnit Foundation continues. Version 11.0.0 was published on 17 July, 2019. This release provides significant enhancements to support alternate technologies like Cucumber.
The README documentation has been updated to show a greatly simplified Java agent idiom for standard projects, and now also shows the Java agent idiom for Android projects.