我正在尝试一个简单的HelloWorld示例。这是我的目录结构:
hello
build.sbt
main
scala
Hello.scala
test
scala
HelloTest.scala
Hello.scala
包含sayHello
函数,我试图通过HelloTest.scala
中的简单测试调用该函数。这是我的build.sbt:
name := "Hello"
organization := "tycon"
scalaVersion := "2.11.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1" % "test"
这是一个不运行任何测试的sbt运行:
$ sbt
[info] Set current project to scala (in build
file:~/git/scala/hello/main/scala/)
> compile
[info] Updating
{file:~/git/scala/hello/main/scala/}scala...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to
~/git/scala/hello/main/scala/target/scala-2.10/classes...
[success] Total time: 3 s, completed Sep 17, 2014 9:04:00 AM
> test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for test:test
[success] Total time: 0 s, completed Sep 17, 2014 9:04:03 AM
我尝试了其他答案中的建议:将%%
替换为%
,将scalatest_2.10
替换为scalatest
中的libraryDependencies
,并将scalaVersion更改为2.10.0
}。他们都没有工作。是的,我reload
每次都build.sbt
改变了。
我相信我遗漏了一些非常基本的东西。我将不胜感激任何帮助。我是Scala的新手。
编辑:为了完整起见,这里有两个scala文件:
Hello.scala:
trait Hello {
def sayHello () = {
println ("Hello, World!")
}
}
HelloTest:阶:
import org.scalatest.FunSuite
class HelloTest extends FunSuite with Hello {
test("say hello") {
sayHello()
}
}
Edit2:我改变了ajozwik和Gabriele建议的目录结构,但是sbt仍然没有运行测试:
~/git/scala/hello/src/main/scala$ sbt
[info] Set current project to scala (in build
file:~/git/scala/hello/src/main/scala/)
> test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for test:test
[success] Total time: 1 s, completed Sep 17, 2014 9:36:24 AM
答案 0 :(得分:4)
目录结构应该是
hello
build.sbt
src
main
scala
Hello.scala
test
scala
HelloTest.scala
即。你错过了外src
目录。
此外,您需要从项目的根目录运行sbt
,而不是从子文件夹中运行。