[英]How to find things and install them with Scala sbt?
我是 Scala 的新手,在 sbt 和安装东西上苦苦挣扎。 例如:
我想在 Eclipse 中开发,因此使用 JUnit。 根据:
http://www.scalatest.org/user_guide/using_junit_runner
“ScalaTest 包括一个 JUnit Runner”,似乎并非如此。 至少对我来说不是。 (我得到object is not a member of package org.scalatest
当我尝试import org.scalatest.junit.JUnitRunner
import org.scalatest.flatspec.AnyFlatSpec
我该如何安装它? 我查看了我的 sbt 文件,其中包含以下行:
libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.1" % "test"
并认为可以,所以我需要 org.scalatest.junit 并尝试像这样添加它:
libraryDependencies += "org.scalatest" %% "junit" % "3.1.1"
这当然给了我三个(:)屏幕:
Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.scalatest:junit_2.12:3.1.1
[error] Not found
(为什么如此重复?它只是一件事没有找到,但它抱怨它就像四次一样!)
我如何弄清楚如何安装这样的东西? 现在我正在尝试一种猜测和随机谷歌搜索的组合方法,有时它有效,有时(就像现在)它对我来说失败了......
在 ScalaTest 3.1.x 中使用 JUnit 运行器执行 ScalaTest 的套件,将以下依赖项添加到build.sbt
libraryDependencies ++= List(
"org.scalatest" %% "scalatest" % "3.1.1" % Test,
"org.scalatestplus" %% "scalatestplus-junit" % "1.0.0-M2" % Test
)
并像这样注释套件
import org.junit.runner.RunWith
import org.scalatestplus.junit.JUnitRunner
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
@RunWith(classOf[JUnitRunner])
class HelloSpec extends AnyFlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
}
更新文档存在一个未解决的问题: Document how to use JUnitRunner in 3.x #1780
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.