NoSuchMethodError while running Scalatest
Asked Answered
A

2

7

I have created one small program and in order to test it I have write small Scala Test class. But when I tried to execute scala test I was getting below error, please advise,

java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
    at org.scalatest.tools.Runner$.argTooShort$1(Runner.scala:1490)
    at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1507)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:898)
    at org.scalatest.tools.Runner$.run(Runner.scala:858)
    at org.scalatest.tools.Runner.run(Runner.scala)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:137)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Aphonic answered 12/12, 2014 at 23:9 Comment(1)
Try not to run tests in Idea but in SBT. Idea sometimes mess up something.Alliber
A
7

I got the resolution. Thanks all for you reply.

There was a problem with my Scatatest version.

I am using Scala version 11 and scalatest version is not compatible with with Scala version.

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"

Above line added in .sbt file and refreshed. Now it works fine as expected.

Aphonic answered 13/12, 2014 at 9:49 Comment(0)
T
0

I was able to mitigate the error by moving to scala 2.12.11 from 2.12.13 and here's how my pom looks like:

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

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.7</version>
          <configuration>
            <skipTests>true</skipTests>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.scalatest</groupId>
          <artifactId>scalatest-maven-plugin</artifactId>
          <version>2.0.0</version>
          <configuration>
            <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
            <junitxml>.</junitxml>
            <filereports>WDF TestSuite.txt</filereports>
          </configuration>
          <executions>
            <execution>
              <id>test</id>
              <goals>
                <goal>test</goal>
              </goals>
            </execution>
          </executions>
        </plugin>`
Tommie answered 27/8, 2024 at 20:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.