[GRADLE-538] Test detection seems to think that every class under src/test/java is a test class Created: 11/Jul/09  Updated: 04/Jan/13  Resolved: 13/Jul/09

Status: Resolved
Project: Gradle
Affects Version/s: 0.6.1
Fix Version/s: 0.7

Type: Bug
Reporter: Peter Niederwieser Assignee: Tom Eyckmans
Resolution: Fixed Votes: 0

Attachments: Zip Archive gradletest.zip    
Issue Links:
Duplicate
Duplicated by GRADLE-540 scanForTestClasses=false has no effect Resolved

 Description   

Unzip the attached sample project and run gradle clean test.

Side notes:

  • If the dependencies section in build.gradle is removed, several not so nice exceptions occur.
  • JIRA lists 0.6.1 under "Unreleased Versions".


 Comments   
Comment by Tom Eyckmans [ 12/Jul/09 ]

Hi Peter,

Thanks for pointing this out, this is odd behavior indeed.

I've checked this out and the test detection is working properly (no test classes detected), in debug logging it is also visible that the classes are discarded:
monospaced
01:33:40.777 [main] DEBUG o.g.a.tasks.testing.TestClassScanner - test-class-scan : scanning apackage/AnotherJavaClass.class
01:33:40.787 [main] DEBUG o.g.a.tasks.testing.TestClassScanner - test-class-scan : discarded apackage/AnotherJavaClass.class not a test class
01:33:40.788 [main] DEBUG o.g.a.tasks.testing.TestClassScanner - test-class-scan : scanning apackage/JavaAnnotationWithClassRetention.class
01:33:40.788 [main] DEBUG o.g.a.tasks.testing.TestClassScanner - test-class-scan : discarded apackage/JavaAnnotationWithClassRetention.class not a test class
monospaced

The includes/excludes passed to the Ant JUnit/TestNG task end up empty which cause JUnit / TestNG to include all classes in the test run (which I didn't anticipate).

Possible solution -> skip test execution and fail the build (can be disabled) - also put this up for discussion on the dev list, feedback more welcome.

Regarding your comment on the dependencies section in the build file, we don't automatically add dependencies (so you are alway in control) so yes you always need to specify a junit / testng dependency. This is normally not an issue since you need to include junit / testng in the testCompile dependency configuration because otherwise the test won't compile.

I've mentioned the unreleased version issue to Hans, waiting for feedback on that.

Comment by Peter Niederwieser [ 13/Jul/09 ]

> we don't automatically add dependencies (so you are alway in control)
Yes I know, and I like it.

> so yes you always need to specify a junit / testng dependency. This is normally not an issue since you need to include junit / testng in the testCompile dependency configuration because otherwise the test won't compile.

I think Gradle should be more graceful here. Say I'm using a test framework that's not yet supported by Gradle and which doesn't depend on JUnit. Then it's certainly OK for Gradle not to run my tests, but it shouldn't crash either. Another scenario is that I've only written a test helper class so far and not yet added the JUnit dependency. Again, Gradle shouldn't crash.

Comment by Tom Eyckmans [ 13/Jul/09 ]

Hi Peter,

When no test are found by the test detection (based on class files scanning and/or includes/excludes) the test execution is skipped, this also solves the issue when there are only support classes in the test sources because the JUnit task is not executed and therefore the JUnit dependency is not needed.

This results in an empty JUnit report and no report in case of TestNG.

Generated at Wed Jun 30 11:32:40 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.