Can’t run Scalatest with Gradle

Spread the love

Question Description

task scalaTest(dependsOn: testClasses) << {
    description = 'Runs Scalatest suite'
    ant.taskdef(name: 'scalatest',
            classname: '',
            classpath: sourceSets.test.runtimeClasspath.asPath
    ant.scalatest(runpath: sourceSets.test.output.classesDir,
            haltonfailure: 'true', fork: 'false') {
        reporter(type: 'stdout')

I run gradle scalaTest and I get:

* What went wrong:
Execution failed for task ':scalaTest'.
> java.lang.NoClassDefFoundError: scala/reflect/ClassManifest$

I am using Scala 2.10.2 and Gradle 1.7

dependencies {
    compile 'org.scala-lang:scala-library:2.10.2'   
    testCompile 'org.scalatest:scalatest:1.3'
    testCompile 'org.scalamock:scalamock_2.10:3.0.1'

What's wrong??

Practice As Follows

I do not know how to solve this one, but I can offer you a workaround. Annotate your test classes with @RunWith(classOf[JUnitRunner]), like this:

import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith

class MyTest extends FunSpec{

and then, gradle test should work.


My dependencies:

compile "org.scala-lang:scala-library:2.10.1"
testCompile "org.scalatest:scalatest_2.10:1.9.1"

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.