# Why does the test task ignore classes I added to the testRuntime classpath?

**URL:** <https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980>\
**Category:** Old Forum Archive\
**Created:** [November 30, 2011, 7:43am UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980 "2011-11-30T07:43:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaus\_illusioni](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@klaus\_illusioni](https://discuss.gradle.org/u/klaus_illusioni)\
**Post date:** [November 30, 2011, 7:43am UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/1 "2011-11-30T07:43:00Z")

</div>

Please help me,

I want to automate testing my students’ turnins. Therefore I copy a build.gradle file into each turnin directory and run a build. Since I have a set of compiled JUnit tests in another project, I added the directory with the .class files to the testRuntime classpath. Unfortunately the test task ignores the classes and executes 0 tests. What’s my mistake?

```gradle
//This build file will be used on each turnin
  apply plugin: 'java'
apply plugin: 'eclipse'
  repositories {
 mavenCentral()
}
  dependencies {
 testCompile 'junit:junit:4.10'
 testCompile 'org.hamcrest:hamcrest-all:1.1'
 testRuntime files('../../turnin-tests/build/classes/test')
}
  sourceSets {
 main {
  java {
   srcDir '.'
  }
 }
}
  test.doFirst {
 println "${project.sourceSets.test.runtimeClasspath.files.join('\n')}"
}

```

```gradle
mak:00864359 klaus$ pwd
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-explode/00864359
mak:00864359 klaus$ ll
total 48
drwxr-xr-x@
7 klaus
staff
 238 30 Nov 08:39 .
drwxr-xr-x
35 klaus
staff
1190 30 Nov 08:20 ..
-rw-r--r--
 1 klaus
staff
4951 30 Nov 06:57 ICEControlCenter.java
-rw-r--r--
 1 klaus
staff
 931 30 Nov 06:21 SlidingWindow.java
-rw-r--r--
 1 klaus
staff
1465 30 Nov 06:49 Wagon.java
-rw-r--r--
 1 klaus
staff
1721 30 Nov 06:21 Worm.java
-rw-r--r--
 1 klaus
staff
 425 30 Nov 08:28 build.gradle
mak:00864359 klaus$ ll ../../turnin-tests/build/classes/test
total 56
drwxr-xr-x
8 klaus
staff
 272 30 Nov 08:10 .
drwxr-xr-x
4 klaus
staff
 136 30 Nov 08:10 ..
-rw-r--r--
1 klaus
staff
5891 30 Nov 08:10 ICEControllerCenterTestBasic.class
-rw-r--r--
1 klaus
staff
2194 30 Nov 08:10 ICEControllerCenterTestFreeTracks.class
-rw-r--r--
1 klaus
staff
1785 30 Nov 08:10 ICEControllerCenterTestShorten.class
-rw-r--r--
1 klaus
staff
2916 30 Nov 08:10 SlidingWindowTest.class
-rw-r--r--
1 klaus
staff
2105 30 Nov 08:10 WagonTest.class
-rw-r--r--
1 klaus
staff
3861 30 Nov 08:10 WormTest.class
mak:00864359 klaus$ gradle test
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-explode/00864359/build/classes/test
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-explode/00864359/build/resources/test
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-explode/00864359/build/classes/main
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-explode/00864359/build/resources/main
/Users/klaus/Documents/dritte/hm/2011-se1/turnin-tests/build/classes/test
/Users/klaus/.gradle/caches/artifacts-4/junit/junit/c12498cf18507aa6433a94eb7d3e77d5/jars/junit-4.10.jar
/Users/klaus/.gradle/caches/artifacts-4/org.hamcrest/hamcrest-all/c12498cf18507aa6433a94eb7d3e77d5/jars/hamcrest-all-1.1.jar
/Users/klaus/.gradle/caches/artifacts-4/org.hamcrest/hamcrest-core/c12498cf18507aa6433a94eb7d3e77d5/jars/hamcrest-core-1.1.jar

```

The directory build/test-results is empty, and the test report html file says 0 tests were executed. :-?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 30, 2011, 12:46pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/2 "2011-11-30T12:46:00Z")

</div>

To add the contents of a directory to a configuration, you need to use ‘fileTree()’, not ‘files()’. The latter just gives a ‘flat’ collection of one or more File’s.

---

<div class="post-metadata">

**Author:** ![klaus\_illusioni](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@klaus\_illusioni](https://discuss.gradle.org/u/klaus_illusioni)\
**Post date:** [November 30, 2011, 5:18pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/3 "2011-11-30T17:18:00Z")

</div>

Hi Peter, a Thanks for your answer. Unfortunately replacing ‘files()’ with ‘fileTree()’ doesn’t solve my issue. Actually ‘project.sourceSets.test.runtimeClasspath’ looked better before, since it contained the directory.

Any further ideas?

Regards, Klaus

---

<div class="post-metadata">

**Author:** ![klaus\_illusioni](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@klaus\_illusioni](https://discuss.gradle.org/u/klaus_illusioni)\
**Post date:** [November 30, 2011, 5:22pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/4 "2011-11-30T17:22:00Z")

</div>

Hi Peter, a Thanks for your answer. Unfortunately replacing ‘files()’ with ‘fileTree()’ doesn’t solve my issue. Actually ‘project.sourceSets.test.runtimeClasspath’ looked better before, since it contained the directory.

Any further ideas?

Regards, Klaus

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 30, 2011, 5:24pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/5 "2011-11-30T17:24:00Z")

</div>

Have you checked that the file tree that you construct contains the expected classes?

---

<div class="post-metadata">

**Author:** ![klaus\_illusioni](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@klaus\_illusioni](https://discuss.gradle.org/u/klaus_illusioni)\
**Post date:** [November 30, 2011, 5:28pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/6 "2011-11-30T17:28:00Z")

</div>

I found it!

The test task’s property ‘testClassesDir’ was the solution:

```gradle
//This build file will be used on each turnin
  apply plugin: 'java'
apply plugin: 'eclipse'
  repositories {
 mavenCentral()
}
  dependencies {
 testCompile 'junit:junit:4.10'
 testCompile 'org.hamcrest:hamcrest-all:1.1'
}
  sourceSets {
 main {
  java {
   srcDir '.'
  }
 }
}
  test {
 testClassesDir file('../../turnin-tests/build/classes/test')
}

```

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 30, 2011, 5:39pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/7 "2011-11-30T17:39:00Z")

</div>

Yes, you are right. Adding the directory itself was the right thing to do. From what I can see in the source code, Gradle only looks for test classes in build/classes/test (more precisely test.testClassesDir). So your best chance may be to copy your test classes there with a Copy task. Or you turn things around, always execute the build which contains the tests but pull in the code to be tested from different places.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [November 30, 2011, 5:45pm UTC](https://discuss.gradle.org/t/why-does-the-test-task-ignore-classes-i-added-to-the-testruntime-classpath/6980/8 "2011-11-30T17:45:00Z")

</div>

If the project itself doesn’t contain any tests, that’s a good solution.
