junit listener from build.gradle

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

junit listener from build.gradle

Tomek Kaczanowski-3
Hello,

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?

I know Gradle has some test listeners of it own, but I would like to
use what JUnit offers.

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: junit listener from build.gradle

Adam Murdoch

On 22/02/2013, at 8:20 AM, Tomek Kaczanowski wrote:

Hello,

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.


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply | Threaded
Open this post in threaded view
|

Re: junit listener from build.gradle

Tomek Kaczanowski-3
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?

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: junit listener from build.gradle

Adam Murdoch

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

Reply | Threaded
Open this post in threaded view
|

Re: junit listener from build.gradle

Tomek Kaczanowski-3
Hm, are you sure? Maven Surefire supports this since few versions
(http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
see "listeners" section).

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com


2013/2/22 Adam Murdoch <[hidden email]>:

>
> 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
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email