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

编程入门 行业动态 更新时间:2024-10-20 00:42:42
本文介绍了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"代替实际
  • 我键盘上的魔术仪式

没有任何作用

有什么主意吗?

推荐答案

您应该查看 sbt项目结构:

src/ main/ resources/ <files to include in main jar here> scala/ <main Scala sources> java/ <main Java sources> test/ resources <files to include in test jar here> scala/ <test Scala sources> java/ <test Java sources>

您的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).

更多推荐

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

本文发布于:2023-11-25 15:26:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630294.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   成员   scalatest   org

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!