Question

src/main/scala/Testing.scala

package common
object Add1Method {
  def main(args: Array[String]) = 100+2
  }

project/build.sbt

name := "Foo"

version := "1.0"

scalaVersion := "2.10.2"

libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"

resolvers +=  "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

resolvers +=  "Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases"

src/test/scala/Test.scala

package test

import common.Testing
import org.scalatest._

class Test extends FlatSpec with Matchers {

      "running main" should "return 102" in {
        val result = Add1Method.main(Array("asdf"))
        assert(result == 102)
      }
    }

But, when I run test from SBT, the following 4 compile-time errors:

[error] Test.scala:4: object scalatest is not a member of package org
[error] import org.scalatest._
[error]            ^
[error] Test.scala:6: not found: type FlatSpec
[error] class Test extends FlatSpec with Matchers {
[error]                        ^
[error] Test.scala:6: not found: type Matchers
[error] class Test extends FlatSpec with Matchers {
[error]                                      ^
[error] Test.scala:8: value should is not a member of String
[error]   "running main" should "return 102" in {
[error]                          ^
[error] four errors found

Note that I tried the suggested answer in SBT not finding scalatest for scala 2.10.1 without success.

The ScalaTest example uses the same imports - http://www.scalatest.org/quick_start.

Was it helpful?

Solution

I think the problem is that your build.sbt is in the wrong place. It should not be in project/ but in the root directory, next to the src directory.

See Directories in the sbt documentation for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top