Howto run Scala tests with Gradle

Compiling Scala code with Gradle 1.4 is smooth. Running Scala tests with Gradle 1.4 seems not well supported, yet. I used the following Ant-based code.

{code} apply plugin: ‘scala’

repositories {

mavenCentral() }

dependencies {

compile ‘org.scala-lang:scala-library:2.10.0’

testCompile ‘org.scalatest:scalatest_2.10:1.9.1’ }

tasks.withType(ScalaCompile) {

// use zync-based incremental compiler

scalaCompileOptions.useAnt = false }

task scalaTest(dependsOn: testClasses) << {

ant.taskdef(name: ‘scalatest’,

classname: ‘org.scalatest.tools.ScalaTestAntTask’,

classpath: sourceSets.test.runtimeClasspath.asPath

)

ant.scalatest(runpath: sourceSets.test.compileClasspath,

fork: ‘false’,

haltonfailure: ‘true’,

suite: ‘TranslatorTest’)

{ reporter(type: ‘stdout’) } } {code}

  1. Can someone please comment if this is currently the best way to run Scala tests?

  2. How can I make the scalaTest task participate in the incremental build when using the zync based compiler? (I’m not sure how I have to defined the inputs and outputs)

  3. How can I configure ant.scalatest such that the scalatest output is printed on the console even if I don’t explicitly run the Gradle build with the -i option?

  4. Do you plan to provide a ScalaTest task as part of the Gradle scala plugin?

Thanks for any help. Regards, Etienne

I recommend to run your ScalaTest tests as JUnit tests. Then you can exploit all Gradle features (parallel execution, reports, etc.). The key for dedicated ScalaTest/specs2/etc. support is to enhance the ‘Test’ task so that new test framework providers can be plugged in (by everyone). This is certainly on our list, but I can’t say when it will happen.

It think this covers 1. and 4. Regarding 2.: I don’t understand how the question is related to Zinc, but you can do the usual ‘task.inputs…’ and ‘tasks.outputs…’ to describe inputs and outputs of the task (see Gradle User Guide). Regarding 3., you should be able to raise the logging level for a particular task (e.g. ‘scalaTast.logging.level = LogLevel.INFO’), but to be honest I’m not sure if it’s currently working.

Thanks for the clarification.

It would be great to have the testing framework configuration that you have mentioned: http://issues.gradle.org/browse/GRADLE-2659

Setting the log level on a specific task does not seem to work: http://issues.gradle.org/browse/GRADLE-2658

I guess, for now, running the tests as JUnit tests with Gradle and as ScalaTests from within the IDE might be an acceptable compromise: http://www.scalatest.org/getting_started_with_junit_4_in_scala