gpt4 book ai didi

Scalatest 在 Intellij 13.1 中不起作用

转载 作者:行者123 更新时间:2023-12-05 00:24:40 25 4
gpt4 key购买 nike

我似乎无法让 Intellij 13.1 运行我的测试。我创建了一个简单的项目来尝试隔离问题,但它也无法在那里工作。这是我的设置:

  • Intellij 13.1 针对 JDK 1.6(需要使用 Java 库)
  • SBT 支持的 Scala 2.10 项目
  • 最新的 scalatest (libraryDependencies += "org.scalatest"% "scalatest_2.11"% "2.2.1"% "test")

  • 这是苏特:
    object Calc {
    def add(a: Int, b: Int) = {
    a + b
    }
    }

    这是测试:
    import org.scalatest.FunSuite

    class Calc$Test extends FunSuite {
    test("two number should add") {
    assert(Calc.add(2, 5) == 7)
    }
    }

    这是我得到的错误:

    Error:scalac: while compiling: /Users/test-user/Development/temp/sample/src/test/scala/Calc$Test.scala during phase: typer library version: version 2.10.4 compiler version: version 2.10.4 reconstructed args: -nobootcp -javabootclasspath : -classpath /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/deploy.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/dt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javaws.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jconsole.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/management-agent.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/plugin.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/sa-jdi.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar:/Users/test-user/Development/temp/sample/target/scala-2.10/test-classes:/Users/test-user/Development/temp/sample/target/scala-2.10/classes:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-library.jar:/Users/test-user/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.2.jar:/Users/test-user/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.2.jar:/Users/test-user/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.2.jar:/Users/test-user/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.1.jar:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-reflect.jar:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-compiler.jar last tree to typer: Apply(method ==) symbol: method == in class Int (flags: ) symbol definition: def ==(x: Int): Boolean tpe: Boolean symbol owners: method == -> class Int -> package scala context owners: value -> class Calc$Test -> package == Enclosing template or block == Template( // val : in class Calc$Test "FunSuite" // parents ValDef( private "_" ) // 2 statements DefDef( // def (): Calc$Test in class Calc$Test "" [] List(Nil) // tree.tpe=Calc$Test Block( // tree.tpe=Unit Apply( // def (): org.scalatest.FunSuite in class FunSuite, tree.tpe=org.scalatest.FunSuite Calc$Test.super."" // def (): org.scalatest.FunSuite in class FunSuite, tree.tpe=()org.scalatest.FunSuite Nil ) () ) ) Apply( Apply( "test" "two number should add" ) Apply( "assert" Apply( // def ==(x: Int): Boolean in class Int, tree.tpe=Boolean Calc.add(2, 5)."$eq$eq" // def ==(x: Int): Boolean in class Int, tree.tpe=(x: Int)Boolean 7 ) ) ) ) == Expanded type of tree == TypeRef(TypeSymbol(final abstract class Boolean extends AnyVal)) uncaught exception during compilation: scala.MatchError



    知道可能是什么问题吗?我认为这是由一个简单的配置问题引起的,因为代码尽可能简单。

    最佳答案

    您显然遇到的一个问题是,您要求使用为 Scala 2.11 编译的 scalatest 版本,但您说您使用的是 Scala 2.10。您需要在 build.sbt 中使用“scalatest_2.10”而不是“scalatest_2.11”。用

    libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.2.1" % "test"

    或者甚至
    libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1" % "test"

    自动获取您的 Scala 版本(注意更改为双百分比:%%。)

    关于Scalatest 在 Intellij 13.1 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25773740/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com