mana
mana

Reputation: 6547

Running Scala test with gradle scala plugin

Using the latest version of gradle (2.10) with the Scala Plugin enabled, I'm trying to execute the tests located at src/test/scala.

But there seems to be no tasks to run these:

$ ./gradlew tasks
....
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

None of these 2 tasks will execute my Scala tests. The only tests that get executed are those in src/test/java. My Scala tests tests are using Specs2 using the following dependencies for test (build.gradle):

apply plugin: 'scala'

dependencies {
    testCompile(
        'org.specs2:specs2-core_2.12.0-M3:3.6.6-scalaz-7.2.0'
    )
}

I checked: the tests are getting compiled when using ./gradlew compileTestScala.

What needs to be done to execute these tests?

Upvotes: 4

Views: 2635

Answers (2)

le cuong
le cuong

Reputation: 11

Another solution: using gradle plugin com.github.maiflai.scalatest

For such solution, Scala tests will be ran using org.scalatest.tools.Runner.

dependencies {
    implementation 'org.scala-lang:scala-library:2.13.3'
    testImplementation 'org.scalatest:scalatest_2.13:3.2.0'
    testImplementation 'junit:junit:4.13'
    testImplementation 'com.vladsch.flexmark:flexmark-all:0.35.10'
}

version of flexmark is important because of scalatest framework hard coded such version in their code

Upvotes: 0

mana
mana

Reputation: 6547

Ok, it was easy:

import org.specs2.runner.JUnitRunner
@RunWith(classOf[JUnitRunner])
class FooSpec extends Specification {
  // test code
  ...
}

Upvotes: 3

Related Questions