简单的scalatest项目不会被编译

我只是遵循Scala Cookbook

但如果我试图运行基本测试,它将不会被编译,因为未解决的软件包库。

这是我的代码...

build.sbt

name := "BasicProjectWithScalaTest"

version := "1.0"

scalaVersion := "2.10.3"

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

* Hello.scala *

package com.alvinalexander.testproject

object Hello extends App {
  val p = Person("Avlin Alexander")
  println("Hello from " + p.name)
}

case class Person(var name: String)

HelloTest.scala

package com.alvinalexander.testproject

import org.scalatest.FunSuite

class HelloTests extends FunSuite {
  test("the name is set correctly in constructor") {
    val p = Person("Barney Rubble")
    assert(p.name == "Barne Rubble")
  }

  test("a Person's name can be changed") {
    val p = Person("Chad Johnson")
    p.name = "Ochocinco"
    assert(p.name == "Ochocinco")
  }
}

如果运行sbt compile ,它会抱怨...

[info] Set current project to BasicProjectWithScalaTest (in build file:/Users/hongseok/dev/scala/test/)
[info] Updating {file:/Users/hongseok/dev/scala/test/}test...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/hongseok/dev/scala/test/target/scala-2.10/classes...
[error] /Users/hongseok/dev/scala/test/src/main/scala/HelloTest.scala:3: object scalatest is not a member of package org
[error] import org.scalatest.FunSuite
[error]            ^
[error] /Users/hongseok/dev/scala/test/src/main/scala/HelloTest.scala:5: not found: type FunSuite
[error] class HelloTests extends FunSuite {
[error]                          ^
[error] /Users/hongseok/dev/scala/test/src/main/scala/HelloTest.scala:6: not found: value test
[error]   test("the name is set correctly in constructor") {
[error]   ^
[error] /Users/hongseok/dev/scala/test/src/main/scala/HelloTest.scala:11: not found: value test
[error]   test("a Person's name can be changed") {
[error]   ^
[error] four errors found
[error] (compile:compile) Compilation failed

build.sbt位于test目录中,Hello.scala位于test / src / main / scala中,而HelloTest.scala位于test / src / test / scala中

我可以在.ivy2目录中找到scalatest_2.10-1.9.2.jar。

为什么图书馆无法解决?

顺便说一句,我使用的是OSX Mountain Lion,0.13,Scala 2.10.3。


pedrofurla写道:

约定是src/main/scalasrc/test/scala

OP写道:

我在文件位置上犯了错误。 如果我纠正它,运作良好。

链接地址: http://www.djcxy.com/p/75033.html

上一篇: Simple scalatest project won't be compiled

下一篇: MySQL table partition by month