On 22/02/2013, at 10:23 AM, Tomek Kaczanowski wrote:
> Hello Adam,
>
>> I can not find way to instruct gradle to use JUnit listeners
>> (extending JUnit TestWatcher). What should I put in the test {}
>> section of my build.gradle so it uses com.mypackage.MyListener while
>> running JUnit tests?
>> TestWatchers are just JUnit rules, so you use them the same way as any rule
>> in JUnit: Attach the watcher to a test class as a field with an @Rule or
>> @ClassRule annotation.
> Thanks, but that is not it. :) I want to specify my listener globally,
> let us say for all tests. Gradle used to allow it - at least for
> TestNG
> (http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-addlisteners).
> I would like to do the same for JUnit. Is it supported?
No. TestNG has explicit support for adding listeners from the launcher, JUnit
does not.
We could probably add something, but it wouldn't be a standard thing, it would
be a Gradle specific extension to JUnit. I don't think JUnit gives us the hooks
to mix a rule into every test. We'd have to invent something, perhaps
generating a Suite class dynamically that wraps all the test classes or
something like that.
--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com