0

Relatively new to sbt and Mockito.

I want to use Mockito in tests, but I'm getting errors related to the Mockito imports when I compile the tests

Imports in test file:

import org.scalatest._
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar

sbt file:

name := "blah"

version := "0.1"

scalaVersion := "2.13.0"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"
libraryDependencies += "org.mockito" % "mockito-core" % "1.8.5" % "test"

I get these error messages when the tests (fail to) compile:

object mockito is not a member of package org [error] import org.mockito.Mockito._

and also:

Symbol 'type org.mockito.MockSettings' is missing from the classpath. [error] This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'.

I've had a play around with changing some of the versions of scalatest and mockito in the sbt file, but not really if that's getting at the root of the problem or not.

Thanks for any help!

Bex
  • 27
  • 2
  • 6

2 Answers2

2

You're using a very old version of Mockito, which is older than the one Scalates relies on, you probably need some 2.x.x version.

On the other hand, I'd recomend you to go fo mockito-scala rather than mockito-core and skip the Scalatest provided classes altogether as they are quite basic.

ultrasecr.eth
  • 1,437
  • 10
  • 13
  • Thanks, updating the version of mockito worked for me (I was originally using the same versions of dependencies as in our production repo and that works, but maybe there's some indirection in there somewhere) – Bex Jul 15 '19 at 08:42
  • Could you please then mark the answer as correct and upvote ;) – ultrasecr.eth Jul 15 '19 at 09:27
1

I suspect you have a caching problem. This happens especially with Intellij.

Here 2 ideas:

Let me know if it is not related with Intellij

pme
  • 14,156
  • 3
  • 52
  • 95