使用SBT无法在Scala测试中运行`test`

时间:2014-02-04 21:39:17

标签: scala sbt scalatest

的src /主/阶/ Testing.scala

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

项目/ 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

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)
      }
    }

但是,当我从SBT运行test时,出现以下4个编译时错误:

[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

请注意,我在SBT not finding scalatest for scala 2.10.1中尝试了建议的答案但没有成功。

ScalaTest示例使用相同的导入 - http://www.scalatest.org/quick_start

1 个答案:

答案 0 :(得分:4)

我认为问题是您的build.sbt位置错误。它不应该在project/中,而应该在根目录中,位于src目录旁边。

有关详细信息,请参阅sbt文档中的Directories