1

I am trying to follow the Scala tutorial and am getting the error object scalatest is not a member of package org. All of the other instances of this error I can find here and on the web have the problem that the test file isn't under src/test, but that's not the case for me. I repeat, for the sake of those who keep marking this as a duplicate, the test file is under src/test, so that is not the problem. My build.sbt file says:

name := "TestExercise"

version := "0.1"

scalaVersion := "2.12.6"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"

src/main/scala/CubeCalculator says:

object CubeCalculator extends App {
  def cube(x: Int) = {
    x * x * x
  }
}

and src/test/scala/CubeCalculatorTest says:

import org.scalatest.FunSuite

class CubeCalculatorTest extends FunSuite {
  test("CubeCalculator.cube") {
    assert(CubeCalculator.cube(3) === 27)
  }
}

(Cut-and-pasted straight from the tutorial.)

So what am I doing wrong? Why can't my project access scalatest?

digitig
  • 1,989
  • 3
  • 25
  • 45
  • 2
    Worth a shot: within the SBT shell, try `reload`, then `clean` and then `compile`. – Lasf Sep 05 '18 at 22:49
  • 1
    are you getting the error in IntelliJ or by running `sbt test` in your shell? you may need to invalidate caches and restart intellij – emran Sep 05 '18 at 23:19
  • I should correct my comment... run `test:compile` or just `test` – Lasf Sep 05 '18 at 23:21
  • clear cache and try again – Raman Mishra Sep 06 '18 at 06:09
  • Possible duplicate of [scalatest : object scalatest is not a member of package org](https://stackoverflow.com/questions/35488213/scalatest-object-scalatest-is-not-a-member-of-package-org) –  Sep 06 '18 at 07:01
  • Not a duplicate, @SundeepPidugu - as I said, I'd already ruled out an incorrect file location. – digitig Sep 06 '18 at 22:52
  • @terminally-chill that, plus a rebuild, did the trick. Thanks. I wish you'd made it an answer rather than a comment, so I could mark it as the answer. – digitig Sep 07 '18 at 19:01

1 Answers1

1

@terminally-chill gave the answer. I am using Intellij, and File | Invalidate caches / restart, followed by a rebuild, resolved the issue.

digitig
  • 1,989
  • 3
  • 25
  • 45