gpt4 book ai didi

scala - 在 IntelliJ 中运行 ScalaTest 时“无法加载 Suite 类”

转载 作者:行者123 更新时间:2023-12-01 23:29:44 35 4
gpt4 key购买 nike

我今天在 Intellij 中运行简单的 TestKit 测试时遇到一些问题。这些测试针对 Scala 代码(我有 Intellij 的 Scala 插件)并且基于 Ray Roestenburg's example .

Intellij 项目是使用“Maven 模块”创建的,然后我添加了所有依赖项并创建了我的项目。测试位于以下位置:

ActorBlast/src/test/scala/basicTest.scala

我基本上是在测试上“右键单击”并选择“运行”。我得到的是以下错误:

"C:\Program Files\Java\jdk1.7.0_25\bin\java" -Didea.launcher.port=7540... Testing started at 2:29 PM ... Unable to load a Suite class. This could be due to an error in your runpath.

Missing class: BasicActorSpec java.lang.ClassNotFoundException: BasicActorSpec at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.scalatest.tools.Runner$$anonfun$35.apply(Runner.scala:2393) at org.scalatest.tools.Runner$$anonfun$35.apply(Runner.scala:2391) at scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:264) at scala.collection.immutable.List.foreach(List.scala:318) at scala.collection.TraversableLike$class.filter(TraversableLike.scala:263) at scala.collection.AbstractTraversable.filter(Traversable.scala:105) at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2391) at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1006) at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1005) at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2659) at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1005) at org.scalatest.tools.Runner$.run(Runner.scala:845) at org.scalatest.tools.Runner.run(Runner.scala) at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:144) at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 0

我不明白这意味着什么。我已经做了很多搜索,但似乎找不到答案。请注意,运行者提示找不到的类是我正在尝试测试/运行的类。 basicTest.scala 如下所示:

// Testing specific imports
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{ShouldMatchers, WordSpecLike, BeforeAndAfterAll}
import akka.testkit.{TestKit, DefaultTimeout, ImplicitSender}
// Actor specific imports
import akka.actor.{ActorRef, Actor, ActorSystem, Props}
// Misc. needed imports
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory


// In order to run tests in this module you need to use JUnitRunner (as per scalatest.org)
@RunWith(classOf[JUnitRunner])
class BasicActorSpec extends TestKit(ActorSystem("BasicActorSpec", ConfigFactory.parseString(BasicActorSpec.config)))
with DefaultTimeout with ImplicitSender with WordSpecLike with ShouldMatchers with BeforeAndAfterAll {

import BasicActorSpec._

val echoRef = system.actorOf(Props[EchoActor])
val forwardRef = system.actorOf(Props[ForwardActor])

override def afterAll {
shutdown(system)
}


/**
* The actual tests...
*/
"An EchoActor" should {
"Respond with the same message it receives" in {
within(500 millis) {
echoRef ! "test"
expectMsg("test")
}
}
}

"A Forwarding Actor" should {
"Forward a message it receives" in {
within(500 millis) {
forwardRef ! "test"
expectMsg("test")
}
}
}

}

/**
* Companion object of test class
*/
object BasicActorSpec {

val config =
"""
|akka {
| loglevel = "Warning"
|}
""".stripMargin

/**
* Classes of Actors used in testing
*/
class EchoActor extends Actor {
def receive = {
case msg => sender ! msg
}
}

class ForwardActor(next: ActorRef) extends Actor {
def receive = {
case msg => next ! msg
}
}

}

任何有关我为何收到此错误的帮助将不胜感激。

最佳答案

运行构建项目 - 它帮助我解决了在尝试解决另一个问题时清除 Cache IDEA :) 时可能发生在我身上的问题

关于scala - 在 IntelliJ 中运行 ScalaTest 时“无法加载 Suite 类”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18838012/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com