【问题标题】:Scala Intellij running test suiteScala Intellij 运行测试套件
【发布时间】:2016-02-08 12:26:33
【问题描述】:

我正在 coursera 上学习 Scala 课程。我正在尝试运行练习中给出的单元测试。但是,我遇到了以下问题:

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
           ^

当我将包导入我的项目时会出现这些:

import org.scalatest.FunSuite

import org.junit.runner.RunWith

我搜索了这个并找到了以下解决方案: 像这样添加依赖项

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

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

【问题讨论】:

  • 你重启sbt了吗?有想法重新导入项目(加载新的依赖项)吗?项目结构的外部库列表中是否出现了新的依赖?

标签: scala intellij-idea build sbt


【解决方案1】:

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

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

然后包含 JUnit(而不是 junit-sbt-interface),可能是这样的:

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

【讨论】:

    猜你喜欢
    • 2014-08-31
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 2018-07-09
    • 2015-11-13
    • 2017-02-15
    相关资源
    最近更新 更多