Abdul Rahman
Abdul Rahman

Reputation: 1384

Dependency Errors scalatest and scala mock

My build.sbt file looks as follows

name := "cakepattern"
version := "0.1"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "3.0.0" % "test",
  "org.scalamock" %% "scalamock-core" % "3.1.1" % "test",
  "org.scalamock" %% "scalamock-scalatest-support" % "3.1.1" % "test",
  "org.scalacheck" %% "scalacheck" % "1.13.0" % "test",
  "org.mockito" % "mockito-all" % "1.10.19"
)

And my scalatest class looks as follows

package services

import config.MockAuthServiceComponent
import dto.{Tweet, User}
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FlatSpec, OneInstancePerTest, Outcome}
import org.scalatest.matchers.MatchResult
import services.impl.DefaultTweetServiceComponent

class DefaultTweetServiceComponentTest extends FlatSpec with MockFactory with OneInstancePerTest{


  val tweetServiceComponent = new DefaultTweetServiceComponent with MockAuthServiceComponent {
    override val tweetService = DefaultTweetService
  }

}

When I try to do sbt test:compile I get the following error

Error:scalac: missing or invalid dependency detected while loading class file 'AbstractMockFactory.class'.
Could not access type NoArgTest in trait org.scalatest.Suite,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'AbstractMockFactory.class' was compiled against an incompatible version of org.scalatest.Suite.

The error seems to go away when I take out MockFactory. Please help, what am I missing.

Thanks!

Upvotes: 1

Views: 1341

Answers (2)

Philipp
Philipp

Reputation: 967

Versions <3.3.0 are not compatible with Scalatest 3+.

I suggest updating to scalamock 3.4.2 (latest one as of writing).

You can always find the newest version on Maven Central.

Also, no need to specify scalamock-core, that gets pulled in automatically.

Upvotes: 0

kikulikov
kikulikov

Reputation: 2583

Do you have any particular reason to use "scalamock-core" % "3.1.1"? It seems to be incompatible with "scalatest" % "3.0.0". It doesn't seem to have the issue if you upgrade to "scalamock-core" % "3.3.0". The code below compiles fine for me:

name := "cakepattern"

version := "0.1"

scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "3.0.0" % "test",
  "org.scalamock" %% "scalamock-core" % "3.3.0" % "test",
  "org.scalamock" %% "scalamock-scalatest-support" % "3.3.0" % "test",
  "org.scalacheck" %% "scalacheck" % "1.13.0" % "test",
  "org.mockito" % "mockito-all" % "1.10.19"
)

scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation", "-encoding", "utf8")

and

import org.scalamock.scalatest.MockFactory
import org.scalatest.{FlatSpec, OneInstancePerTest}

trait MockAuthServiceComponent

trait DefaultTweetServiceComponent {
  val tweetService: DefaultTweetService
}

case class DefaultTweetService()

class DefaultTweetServiceTest extends FlatSpec with MockFactory with OneInstancePerTest {

  val tweetServiceComponent = new DefaultTweetServiceComponent with MockAuthServiceComponent {
    override val tweetService = DefaultTweetService()
  }
}

Upvotes: 2

Related Questions