How does Gradle decide whether a class is a test?

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

How does Gradle decide whether a class is a test?

Peter Niederwieser
Hi,

when building a Java project, how does Gradle decide which classes under src/test/java are tests (and therefore need to be executed), and which are not? (The most elegant solution for JUnit 4 would be to treat a class as a test iff it has at least one method annotated with @Test.)

Cheers,
Peter

PS: Is it possible to disallow posting to the parent forum? I keep falling into this trap.
Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

hans_d
Administrator
Hi Peter,

On May 9, 2008, at 12:18 AM, Peter Niederwieser wrote:

Hi, 

when building a Java project, how does Gradle decide which classes under
src/test/java are tests (and therefore need to be executed), and which are
not? (The most elegant solution for JUnit 4 would be to treat a class as a
test iff it has at least one method annotated with @Test.) 

Gradle itself uses 3.8 conventions for its tests (because IntelliJ did not support JUnit 4 test execution  a while ago).

In such a case have to pass a pattern which tests are included to the test task. The include and exclude pattern are applied to the test-classes folder.

test {    include '**/*Test.class'    exclude '**/Abstract*'    // We set forkmode to ONCE as our tests are written in Groovy and the startup time of Groovy is significant.    options.fork(forkMode: ForkMode.ONCE, jvmArgs: ["-ea", "-Dgradle.home=roadToNowhere"])}
Right now there is no default pattern for inclusions.
Gradle delegated to the Ant JUnit task which works also with JUnit 4. I need to figure out if the JUnit Ant task relies on the same filtering used for 3.8 tests, also for JUnit 4 tests. This would be inconvenient. As you have said above, with JUnit 4 there is an easy way to identify a test. What happens if you include all classes when you have JUnit 4 tests? Does the Ant task throws an exception because it tries to execute a non JUnit test class?


Cheers, 
Peter

PS: Is it possible to disallow posting to the parent forum? I keep falling
into this trap.

I gonna check if this is possible.

- Hans

-- 
Sent from the gradle-user mailing list archive at Nabble.com.


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




--
Hans Dockter
Gradle Project lead




Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

Russel Winder-2
Hans,

On Fri, 2008-05-09 at 10:30 +0200, Hans Dockter wrote:

> Gradle itself uses 3.8 conventions for its tests (because IntelliJ did
> not support JUnit 4 test execution  a while ago).

Can I add a voice for TestNG of which JUnit4 is a pale immitation.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

hans_d
Administrator
Hi Russel,

On May 9, 2008, at 11:11 AM, Russel Winder wrote:
Hans,

On Fri, 2008-05-09 at 10:30 +0200, Hans Dockter wrote:

Gradle itself uses 3.8 conventions for its tests (because IntelliJ did
not support JUnit 4 test execution  a while ago).

Can I add a voice for TestNG of which JUnit4 is a pale immitation.

I have already apologized to Alex for not having it integrated in the build-by-convention configuration yet. This is coming soon.

BUT: You can already use it as easily as you would use it from Ant.

test.doLast {
ant.testng(classpath: dependecies.antpath('testRuntime'), ...) {
            ...
        }
}

- Hans


-- 
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

--
Hans Dockter
Gradle Project lead




Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

Russel Winder-2
Hans,

On Fri, 2008-05-09 at 12:06 +0200, Hans Dockter wrote:
> Hi Russel,


> > Can I add a voice for TestNG of which JUnit4 is a pale immitation.
>
> I have already apologized to Alex for not having it integrated in the
> build-by-convention configuration yet. This is coming soon.

No problem, but the sooner the better :-)

> BUT: You can already use it as easily as you would use it from Ant.
>
>
> test.doLast {
> ant.testng(classpath: dependecies.antpath('testRuntime'), ...) {
>
>             ...
>         }
> }

OK, I will give it a try.  I guess the problem of downloading TestNG is
still there though because of the classifier.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

hans_d
Administrator

On May 9, 2008, at 1:26 PM, Russel Winder wrote:
Hans,

On Fri, 2008-05-09 at 12:06 +0200, Hans Dockter wrote:
Hi Russel,


Can I add a voice for TestNG of which JUnit4 is a pale immitation.

I have already apologized to Alex for not having it integrated in the
build-by-convention configuration yet. This is coming soon.

No problem, but the sooner the better :-)

BUT: You can already use it as easily as you would use it from Ant.


test.doLast {
ant.testng(classpath: dependecies.antpath('testRuntime'), ...) {

            ...
        }
}

OK, I will give it a try.  I guess the problem of downloading TestNG is
still there though because of the classifier.


This is right. You could put it in a FlatDirResolver on your local machine.

- Hans

-- 
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

--
Hans Dockter
Gradle Project lead




Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

hans_d
Administrator
In reply to this post by Peter Niederwieser

On May 9, 2008, at 12:18 AM, Peter Niederwieser wrote:

Hi, 

when building a Java project, how does Gradle decide which classes under
src/test/java are tests (and therefore need to be executed), and which are
not? (The most elegant solution for JUnit 4 would be to treat a class as a
test iff it has at least one method annotated with @Test.) 

Cheers, 
Peter

PS: Is it possible to disallow posting to the parent forum? I keep falling
into this trap.

This is disabled now.

- Hans

-- 
Sent from the gradle-user mailing list archive at Nabble.com.


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




--
Hans Dockter
Gradle Project lead




Reply | Threaded
Open this post in threaded view
|

Re: How does Gradle decide whether a class is a test?

Peter Niederwieser
In reply to this post by hans_d
hdockter wrote
What happens if you include all classes when  
you have JUnit 4 tests? Does the Ant task throws an exception because  
it tries to execute a non JUnit test class?
JUnit 4 complains if a class has no test methods. But with excludes it works just fine.

Meanwhile, thanks to Gradle and your help, my build (using the Groovy 1.6 trunk compiler) is fully working. Yippieh!

Cheers,
Peter