sbt:添加对 Scalatest 库的依赖.在哪里? [英] sbt: Add dependency on scalatest library. Where?
问题描述
我使用 SBT 创建了一个 scala 项目,并使用 scalatest 编写了一些单元测试用例.但不知何故 sbt test
找不到 org.scalatest 包.
I created a scala project using SBT and wrote some unit test cases using scalatest. But somehow sbt test
can't find the org.scalatest package.
这里是我的项目定义文件:
Here my project definition files:
- 源在
src/main/scala 对应的 src/test/scala
build.sbt
:
name := "MyProject"
version := "0.1"
scalaVersion := "2.9.2"
project/plugins.sbt
:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
project/build.sbt
:
libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test"
我使用的是 SBT 0.11.3.
I'm using SBT 0.11.3.
在控制台上使用 sbt compile
编译程序工作正常.此外,我在 ~/.ivy2
中找到了 scalatest jar,所以 SBT 一定已经下载了它.
Compiling the program using sbt compile
on the console works fine.
Furthermore I found the scalatest jar in ~/.ivy2
, so SBT must have downloaded it.
但是当运行 sbt test
时,它说
But when running sbt test
, it says
object scalatest is not a member of package org
[error] import org.scalatest.FlatSpec
...[many errors alike]
并且运行 sbt eclipse
会创建一个不包含 Scalatest jar 的 .classpath.
And running sbt eclipse
creates a .classpath that doesn't contain the scalatest jar.
我是否必须在其他地方指定测试依赖项?我应该如何添加 Scalatest 库?
Do I have to specify the test dependencies somewhere else? How should I add the scalatest library?
推荐答案
将 libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test"
放入 build.sbt,而不是 project/build.sbt.
Place libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test"
into build.sbt, not project/build.sbt.
这篇关于sbt:添加对 Scalatest 库的依赖.在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!