我已经用Scala编程大约一周了,但不是用sbt --我下载了'scala binaries for windows‘(使用Windows10),刚刚开始使用文本编辑器编写脚本,并通过命令行编译和执行,例如
/** Calculate factorial of n
* Pre: n >= 0
* Post: returns n! */
def fact(n: Int) : BigInt = {
require(n>=0)
if(n==0) 1 else fact(n-1)*n
}
// Main method
def main(args: Array[String]) : Unit = {
print("Please input a number: ")
val n = scala.io.StdIn.readInt()
if(n>=0){
val f = fact(n)
println("The factorial of "+n+" is "+f)
}
else println("Sorry, negative numbers aren't allowed")
}
}然后:

到现在为止还好。输入: ScalaTest。
import org.scalatest.funsuite.AnyFunSuite
import Factorial.fact
class FactTest extends AnyFunSuite {
test("0! is 1"){ assert(fact(0) === 1) }
test("5! is 120") { assert(fact(5) === 120) }
test("3! is 5") {assert(fact(3) === 5) } //Want to see what happens when the test isn't passed
}但这不会编译。

我运行的是scala 2.13.4,所以所有版本都是匹配的(我相信?)
我最好的猜测是,我认为scalac实际上并没有找到/使用ScalaTest文件,但我不知道为什么。
有什么帮助吗?
编辑:我已经添加了funsuite scalatest jar,仍然不能工作...

发布于 2021-02-02 06:11:30
解决方案被证明是我试图使用Scalatic和Scalatest的单独版本,尽管它们是最近集成的。
下载并用作类路径scalatest-app_2.13-3.2.2.jar修复了所有问题。
发布于 2021-01-30 23:24:05
主ScalaTest JAR不包含AnyFunSuite。您还需要scalatest-funsuite_2.13-3.2.3.jar。而且主ScalaTest JAR不仅依赖于可伸缩JAR;它还依赖于scalatest-core_2.13-3.2.3.jar,因此您的类路径中也需要它。
也许你还需要一些其他的罐子--我没看。我的回答的重点并不是说“这是您在这个特定情况下需要的特定JAR”。我的回答的重点是教育您--告诉您“一般来说,库具有传递依赖关系,它们可以深入任何级别”,如果在组装类路径时没有考虑到这一点,那么失败是可以预测的。
您可以查看这些JAR的POM,以递归方式找出它们的依赖关系。构建工具将自动为您完成这项工作,并为您组装一个适当的类路径,而无需您经历这些麻烦。
如果您不愿意使用完整的构建工具,但愿意使用一个较小的工具,该工具只为您下载依赖关系树并组装类路径,那么可以考虑使用Coursier。
https://stackoverflow.com/questions/65968374
复制相似问题