我已经用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修复了所有问题。
https://stackoverflow.com/questions/65968374
复制相似问题