scalatest:对象scalatest不是包org的成员

scalatest:对象scalatest不是包org的成员

问题描述:

编辑:如果文件位于src/test/scala/tests/中而不是src/main/scala/mypackage/中,为什么可以使用?

EDIT : it works if the file is in src/test/scala/tests/ but not in src/main/scala/mypackage/ Why ?

我尝试了一些主题的解决方案,人们的问题几乎相同,但没有一个解决问题.

I have try solutions from topics with people having nearly the same issue but none works.

详细信息,我在build.sbt中有此内容:

In details, I have this in build.sbt :

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

在intellij中,一个带有以下内容的类:

In intellij a class with:

import org.scalatest.{BeforeAndAfterAll, Suite}

{BeforeAndAfterAll,Suite}用红色显示,所以我猜发现了scalatest

with {BeforeAndAfterAll, Suite} in red so i guess scalatest is found

sbt软件包也不起作用:

sbt package does not work too :

对象scalatest不是包org的成员[错误]导入 org.scalatest. {BeforeAndAfterAll,Suite}

object scalatest is not a member of package org [error] import org.scalatest. {BeforeAndAfterAll, Suite}

我已经尝试过:

  • sbt干净更新
  • 重新启动+使intellij的缓存无效
  • 删除.idea/并重新导入
  • libraryDependencies + ="org.scalatest"%"scalatest_2.10"%"2.0"%"test"代替实际
  • 我键盘上的魔术仪式

没有任何作用

有什么主意吗?

您应该查看您的Scala测试应该在src/test/scala/下.

Your scala tests should go under src/test/scala/.

如果您真的想在main中使用scalatest(并且知道要执行的操作),请尝试以下操作:

If you really want to use scalatest in main (and you know what you are trying to do), try this:

  "org.scalatest" % "scalatest_2.10" % "2.2.1",

在原始的build.sbt中,"test"是配置,这意味着scalatest仅在测试类路径上,而主要来源则不需要.这对于库来说通常是个好习惯,因为您的用户通常不需要您的测试依赖项就可以使用您的库( ref ).

In your original build.sbt, "test" is the configuration and it means that scalatest will only be on the test classpath and it isn’t needed by the main sources. This is generally good practice for libraries because your users don’t typically need your test dependencies to use your library (ref).