【问题标题】:object junit is not a member of package org对象 junit 不是包 org 的成员
【发布时间】:2019-05-28 21:40:56
【问题描述】:

运行时

sbt 编译

在项目根目录中出现错误:

object junit is not a member of package org
[error] import org.junit.Test

我已经完全定义了 build.sbt:

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v")
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test
libraryDependencies += "junit" % "junit" % "4.12" % "test"

文件 TestSingleLinkedList.scala 也在项目根目录中,并且具有:

import org.junit.Test

【问题讨论】:

  • 你在 src/test 中使用 junit 吗?
  • @galando - 这个错误有很多 stackoverlow 答案 - 我确实检查了每一个并且目前 - 它们不适用。您提供的是关于将 build.sbt 放在根目录中的内容 - 我已经有了。
  • @DraifKroneg - 好的,只是想确认一下 :)

标签: scala junit sbt


【解决方案1】:

在 sbt 中放置 junit 测试似乎唯一有效的是:

├── built.sbt
├── src
│   └── test
│       └── scala
│           ├── X.scala

否则 - sbt 将提供关于不包含 junit 的非常无信息且令人困惑的错误。 我找到了答案 ScalaTest on sbt not running any tests 有人问了关于 sbt 不运行测试的不同问题。 就我而言,sbt - 根本没有编译。

【讨论】:

  • 非常感谢。我犯了一个类似的错误,尝试通过在 src/main/scala 中的文件中导入 junit 来使用 Assert。
猜你喜欢
  • 2016-02-09
  • 2012-12-20
  • 2016-02-29
  • 2019-11-22
  • 2016-05-31
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多