Running ScalaTest suites

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

Running ScalaTest suites

David Rosell
Since the Scala plugin doesn't recognize ScalaTest unit test's I call the Ant task "org.scalatest.tools.ScalaTestAntTask"
However, I'm kind of groovy illiterate and do the gradle scripting copy past style and need some hints how to copy better :)

This is what I came up with:
task scalatest << {
  ant.taskdef(
          name: 'scalatest',
          classname: 'org.scalatest.tools.ScalaTestAntTask',
          classpath: configurations.compile.asPath + ':' + compileScala.destinationDir
  )
  ant.scalatest(
          runpath: 'build/classes/test',
          haltonfailure: 'true',
          fork: 'false'
  )
}

1: I'm not happy about the runpath value, is there a better way to refere to the compiled tests?

2: Then there are tags inside the scalatest ant declaration (ie. reporter), how do I set these?

   <target name="test" depends=""> 
     <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestAntTask"> 
       <classpath refid="scalatest.classpath"/> 
     </taskdef> 
     <scalatest runpath="${test.classes} " haltonfailure="true" fork="false"> 
        <reporter type="stdout" /> 
     </scalatest>

3: I would like to snap my scalatest task into the test phase, how is this done?

4: The scala build are a little slow, ~10sek can be a very long time when you do TDD, any tips on how to make it run faster?

Last, I'd like to suggest adding something like this scalatest task to the Scala Plugin section in the documentation, it is nice to have working examples how to extend gradle's capabilities in context, and now that the "run a program" is fixed so that you doesn't need ant for that, this could be another...
  
Regards,
David Rosell
Reply | Threaded
Open this post in threaded view
|

Re: Running ScalaTest suites

Adam Murdoch-3
On 11/07/10 12:41 AM, David Rosell wrote:
Since the Scala plugin doesn't recognize ScalaTest unit test's I call the Ant task "org.scalatest.tools.ScalaTestAntTask"
However, I'm kind of groovy illiterate and do the gradle scripting copy past style and need some hints how to copy better :)

This is what I came up with:
task scalatest << {
  ant.taskdef(
          name: 'scalatest',
          classname: 'org.scalatest.tools.ScalaTestAntTask',
          classpath: configurations.compile.asPath + ':' + compileScala.destinationDir
  )
  ant.scalatest(
          runpath: 'build/classes/test',
          haltonfailure: 'true',
          fork: 'false'
  )
}

1: I'm not happy about the runpath value, is there a better way to refere to the compiled tests?

sourceSets.test.classesDir


2: Then there are tags inside the scalatest ant declaration (ie. reporter), how do I set these?

There's a chapter in the user guide about using Ant. Have a look at http://gradle.org/0.9-preview-3/docs/userguide/ant.html

Basically, you use nested method calls to add nested elements:

ant.scalatest(...) {
    reporter(type: 'stdout')
}


   <target name="test" depends=""> 
     <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestAntTask"> 
       <classpath refid="scalatest.classpath"/> 
     </taskdef> 
     <scalatest runpath="${test.classes} " haltonfailure="true" fork="false"> 
        <reporter type="stdout" /> 
     </scalatest>

3: I would like to snap my scalatest task into the test phase, how is this done?


You can simply replace the test task:

task test(overwrite: true, dependsOn: classes) << {
    ant.taskdef(...)
    ant.scalatest(...)
}


4: The scala build are a little slow, ~10sek can be a very long time when you do TDD, any tips on how to make it run faster?

I made some changes recently which should speed up multiproject scala builds. These changes will end up in the next release of Gradle. They won't make any difference to a single project build. We have also made a bunch of startup time improvements which may make a difference for your build.

Other than that, you could try using fsc rather than scalac. There are some settings on the ScalaCompileOptions class for enabling this.

There is currently a big startup cost when you are using Gradle to build Groovy or Scala projects. We plan to solve this at some point in a general purpose way, that can work for any type of project.


Last, I'd like to suggest adding something like this scalatest task to the Scala Plugin section in the documentation, it is nice to have working examples how to extend gradle's capabilities in context, and now that the "run a program" is fixed so that you doesn't need ant for that, this could be another...

I think I'd rather add ScalaTest support to the test task. I've added an issue for this: http://jira.codehaus.org/browse/GRADLE-1032


-- 
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz
Reply | Threaded
Open this post in threaded view
|

Re: Running ScalaTest suites

mhanco
Adam Murdoch-3 wrote
On 11/07/10 12:41 AM, David Rosell wrote:
> Last, I'd like to suggest adding something like this scalatest task to
> the Scala Plugin section in the documentation, it is nice to have
> working examples how to extend gradle's capabilities in context, and
> now that the "run a program" is fixed so that you doesn't need ant for
> that, this could be another...

I think I'd rather add ScalaTest support to the test task. I've added an
issue for this: http://jira.codehaus.org/browse/GRADLE-1032
Noticed this is still open, the ant task works pretty well though.

test << {
  ant.taskdef( name: 'scalatest', classname:
'org.scalatest.tools.ScalaTestAntTask', classpath: classpath.asPath)
  ant.scalatest( runpath: testClassesDir, haltonfailure: 'true', fork:
'false') {
    reporter(type: 'stderr')
  }
}

If you use 'stdout', you need to run gradle with --info to see the details.

If you want to replace the test task, then use the classpath and runpath as
shown below:

task test(overwrite: true, dependsOn: compileTestScala) << {
  ant.taskdef(
    name: 'scalatest',
    classname: 'org.scalatest.tools.ScalaTestAntTask',
    classpath:
configurations.testRuntime.asPath+':'+compileScala.destinationDir
  )
  ant.scalatest(
    runpath: sourceSets.test.output.classesDir,
    haltonfailure: 'true',
    fork: 'false'
  ) {
    reporter(type: 'stderr')
  }
}

Mike Hancock