Specifying Unit Test Location in Gradle

I've been getting my feet wet with Gradle for a school project (not an assignment) and I have this project that is divided into two folder, src/main/scala and src/test/scala.

As you can probably tell, the test folder stores my Unit Tests but for some reason I can't get Gradle to find them and tun them as it should. I'm using Scala with ScalaTest for this project.

Is there any way to tell Gradle where to look for test files? Or is there any logical explanation to why it isn't detecting my files?

This is my build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'scala'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        scala {
            srcDirs = ['src/scala']
        }
    }
    test {
        scala {
            srcDirs = ['test/scala']
        }
    }
}

dependencies {
    compile 'org.scala-lang:scala-library:2.10.3'
    testCompile 'junit:junit:4.10'
    testCompile 'org.scalatest:scalatest_2.10:2.1.+'
}

test {
    useJUnit()
    testLogging {
        // Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}   

Answers


As described in the gradle scala plugin, you can change the location of the source and test directory by adding something like the following:

sourceSets {
    main {
        scala {
            srcDirs = ['src/scala']
        }
    }
    test {
        scala {
            srcDirs = ['test/scala']
        }
    }
}

I figured out the correct build.gradle to get it to work thanks to @ditkin 's reply. Turns out I needed to put the full src/main/scala and src/test/scala.

apply plugin: 'scala'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        scala {
            srcDirs = ['src/main/scala']
        }
    }
    test {
        scala {
            srcDirs = ['src/test/scala']
        }
    }
}

dependencies {
    compile 'org.scala-lang:scala-library:2.10.3'
    testCompile 'junit:junit:4.10'
    testCompile 'org.scalatest:scalatest_2.10:2.1.+'
}

test {
    useJUnit()
    testLogging {
        // Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}   

Look here for detailed explanation how test works and configure them http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test


Need Your Help

Mac OSX: NKE iff_event_func on Mountain Lion

macos osx-mountain-lion osx-mavericks kernel-extension

I implemented an iff_event_func callback specifically to detect KEV_DL_IF_DETACHING and KEV_DL_IF_DETACHED events.

Reduce code repetition in express API route

node.js express mongoose

I'm learning express and am currently writing an API, and have this structure: