0
votes

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.

1
The example on the site uses "2.0". I am wondering if you reloaded your sbt.EECOLOR
I updated to libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0" % "test", but same errors when running test.Kevin Meredith
If you do reload then clean and after that test, what is the output? You can put the result in a public gist.EECOLOR
@EECOLOR, same 4 compile-time errors as my above question. Note that I ran reload and clean, and finally test. I understand that you were concerned that I failed to run reload to update my build.sbt settings.Kevin Meredith
Kevin, if you post the same question to both Stack Overflow and a mailing list (scalatest-users), both posts should link to the other, so that people don't waste their time answering something in one place that was already answered in another.Seth Tisue

1 Answers

5
votes

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.