我试图用scala为我的代码编写一些测试,问题是每次我尝试使用sbt运行jacoco时,都会遇到各种各样的错误。
如果这与此有关,我将使用VSCode。
这是测试的代码片段。
package model
import org.scalatest.Wordspec
import org.scalatest.matchers.should.Matchers._
import model._
class fieldSpec extends WordSpec with Matchers {
"A Field" when {
"not set any value" should {
val emptyField = Field(0)
"have value 0" in {
emptyField.value should be(0)
}这是我的build.sbt
val scala3Version = "3.1.1"
lazy val root = project
.in(file("."))
.settings(
name := "MADN",
version := "0.1.0-SNAPSHOT",
scalaVersion := scala3Version,
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.11",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.11" % "test"
)当我试图运行sbt时,我会得到这个错误消息作为输出。
[error] -- [E006] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:7:24
[error] 7 |class fieldSpec extends WordSpec with Matchers {
[error] | ^^^^^^^^
[error] | Not found: type WordSpec
[error] -- [E006] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:7:38
[error] 7 |class fieldSpec extends WordSpec with Matchers {
[error] | ^^^^^^^^
[error] | Not found: type Matchers
[error] -- [E008] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:9:12
[error] 9 | "A Field" when {
[error] | ^^^^^^^^^^^^^^
[error] |value when is not a member of String - did you mean ("A Field" : String).wait?
[error] -- [E006] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:11:23
[error] 11 | val emptyField = Field(0)
[error] | ^^^^^
[error] | Not found: Field
[error] -- [E008] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:12:21
[error] 12 | "have value 0" in {
[error] | ^^^^^^^^^^^^^^^^^
[error] | value in is not a member of String
[error] -- [E008] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:15:19
[error] 15 | "not be set" in {
[error] | ^^^^^^^^^^^^^^^
[error] | value in is not a member of String
[error] -- [E006] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:20:26
[error] 20 | val nonEmptyField = Field(2)
[error] | ^^^^^
[error] | Not found: Field
[error] -- [E008] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:21:26
[error] 21 | "return that value" in {
[error] | ^^^^^^^^^^^^^^^^^^^^^^
[error] | value in is not a member of String
[error] -- [E008] Not Found Error: C:\Software-Engineering\MADN\src\test\scala\model\fieldSpec.scala:24:15
[error] 24 | "be set" in {
[error] | ^^^^^^^^^^^
[error] | value in is not a member of String
[error] 9 errors found
[error] 9 errors found
[error] (Test / compileIncremental) Compilation failed
[error] Total time: 7 s, completed 06.04.2022 14:29:46我还在project/plugins.sbt中包含了插件
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")我的测试位于以下目录: src>test>scala>model>fieldSpec.scala
发布于 2022-04-06 20:31:00
因此,我能够通过使用AnyWordSpec而不是仅仅通过WordSpec来修复它,还可以从build.sbt中删除下面一行
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test,https://stackoverflow.com/questions/71766973
复制相似问题