Search code examples
scalascalatest

Compilation error: error: object scalatest is not a member of package.org, am NOT using sbt


I've been programming in Scala for about a week, but not with sbt - I downloaded the 'scala binaries for windows' (using Windows 10) and have just been writing scripts using a text editor, and compiling and executing via the command line, e.g.

  /** Calculate factorial of n
    * Pre: n >= 0
    * Post: returns n! */
  def fact(n: Int) : BigInt = {
    require(n>=0)
    if(n==0) 1 else fact(n-1)*n
  }

  // Main method
  def main(args: Array[String]) : Unit = { 
    print("Please input a number: ")
    val n = scala.io.StdIn.readInt()
    if(n>=0){
      val f = fact(n)
      println("The factorial of "+n+" is "+f)
    }
    else println("Sorry, negative numbers aren't allowed")
  }
}

and then:

Compiling with scalac and executing via the command line

So far, so good. Enter: ScalaTest.

import org.scalatest.funsuite.AnyFunSuite

import Factorial.fact

class FactTest extends AnyFunSuite {
   test("0! is 1"){ assert(fact(0) === 1) }
   test("5! is 120") { assert(fact(5) === 120) }
   test("3! is 5") {assert(fact(3) === 5) } //Want to see what happens when the test isn't passed
}

But this will not compile.

Attempting to compile gives the object scalatest is not a member of package.org error

I'm running scala 2.13.4, so the versions all match up (I believe?)

My best guess at what's going on is I don't think scalac is actually finding/using the ScalaTest file, but I have no clue why.

Any help?

EDIT: Have added the funsuite scalatest jar, still not working...

Attempted compiling now also using funsuite jar


Solution

  • The solution turned out to be that I was attempting to use seperate versions of Scalatic and Scalatest, despite that they were integrated recently.

    Downloading and using as the classpath scalatest-app_2.13-3.2.2.jar fixed everything.