2015-11-07 122 views
1

我正在做coursera的Scala课程。我正在尝试运行练习中给出的单元测试。但是,我得到了以下问题:斯卡拉Intellij运行测试套件

import org.scalatest.FunSuite 

import org.junit.runner.RunWith 

我GOOGLE了这一点,并找到了以下解决方案: 添加依赖这样

Error:(3, 12) object scalatest is not a member of package org 
import org.scalatest.FunSuite 
     ^

Error:(6, 12) object junit is not a member of package org 
import org.junit.runner.RunWith 
     ^

当我导入包到我的项目,这些出现

libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test->default" 

我试着将此代码添加到build.sbt,但错误仍然存​​在。

+0

你有没有重新启动SBT?有想法重新导入项目(加载新的依赖项)?项目结构的外部库列表中是否出现新的依赖项? – Rumoku

回答

4

ScalaTest不是JUnit。如果您想用sbt直接执行JUnit测试,则需要添加junit-interface。不过,显然你正在尝试运行ScalaTest测试。你所需要的附加库的依赖是

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

然后包括JUnit的(而不是基于JUnit SBT接口),大概是这样的:

libraryDependencies += "junit" % "junit" % "4.12" % "test"