Search code examples
mavenscalatest

Maven not running scala tests


I have following in pom:

<dependency>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest_2.11</artifactId>
        <version>3.0.8</version>
        <scope>test</scope>
</dependency>

Also, made changes as documented here.

And test as:

class MyTest extends FunSuite {
    test("....") {
        assert(2+2 == 4)
    }
}

'mvn clean install' has output as:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Maven is not executing the tests. Why is it so?


Solution

  • It's not an answer to your question, but should allow you to run your tests.

    You could use JUnitRunner and surefire to run your tests.

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    ...
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>4.2.4</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
     ...
    

    And then annotate your test class with:

    @RunWith(classOf[JUnitRunner])
    class MyTest extends FunSuite {