scalatest在intellij 13.1中不起作用

时间:2014-09-10 19:39:33

标签: scala intellij-idea scalatest intellij-13

我似乎无法让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”)

这是sut:

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)
  }
}

这是我得到的错误:

  

错误:scalac:        编译时:/Users/test-user/Development/temp/sample/src/test/scala/Calc$Test.scala           在阶段:typer        库版本:版本2.10.4       编译器版本:版本2.10.4重建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。罐子:/Users/test-user/Development/temp/sample/target/scala-2.10/test-classes:/Users/test-user/Development/temp/sample/target/scala-2.10/classes:/用户/测试-user /名.bst的/ boot /斯卡拉-2.10.4 / lib目录/斯卡拉-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/高速缓存/ org.scala-lang.modules /阶-xml_2.11 /捆绑/阶-xml_2.11-1.0.2.jar:/Users/test-user/.ivy2/ca CHE / org.scalatest / scalatest_2.11 /捆绑/ scalatest_2.11-2.2.1.jar:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-reflect.jar:/用户/test-user/.sbt/boot/scala-2.10.4/lib/scala-compiler.jar   最后一个树到typer:Apply(方法==)                 symbol:method == in class Int(flags :)符号定义:def ==(x:Int):Boolean                    tpe:布尔值          符号所有者:method == - > class Int - >包scala         上下文所有者:值 - > class Calc $ Test - >包   ==封闭模板或块==模板(// val:类Calc $ Test“FunSuite”//父母ValDef(       私人的       “_”                 )// 2语句DefDef(// def():在Calc $ Test类中的Calc $ Test              “”       []       列表(无)        // tree.tpe = Calc $ Test       阻止(// tree.tpe =单位         在FunSuite类中应用(// def():org.scalatest.FunSuite,tree.tpe = org.scalatest.FunSuite           Calc $ Test.super。“”// def():类FunSuite中的org.scalatest.FunSuite,   tree.tpe =()org.scalatest.FunSuite           零         )         ()       ))申请(       应用(         “测试”         “两个数字应该加”       )       应用(         “断言”         Apply(// def ==(x:Int):Int类中的Boolean,tree.tpe = Boolean           Calc.add(2,5)。“$ eq $ eq”// def ==(x:Int):类Int中的布尔值,tree.tpe =(x:Int)布尔值           7         )       )))   ==扩展类型的树== TypeRef(TypeSymbol(最终抽象类布尔值扩展AnyVal))编译期间未捕获的异常:   scala.MatchError

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

2 个答案:

答案 0 :(得分:6)

你明显遇到的一个问题是你要求为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版本(请注意更改为双倍百分比:%%。)

答案 1 :(得分:0)

由于您的项目是2.10支持,因此也可以使用相同版本的scalatest,

scalaVersion := "2.10.5" // don't need to mention scalatest_2.10, will be reflected automatically

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" // works with 2.2.1 or 3.0.0

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"

或使用maven,

<dependency>
    <groupId>org.scalactic</groupId>
    <artifactId>scalactic_2.10</artifactId>
    <version>3.0.0</version>
</dependency>

<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_2.10</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
</dependency>

此处参考http://www.scalatest.org/install