我今天在 Intellij 中运行一个简单的 TestKit 测试时遇到了一些问题。这些测试是针对 Scala 代码的(我有 Intellij 的 Scala 插件)并且基于Ray Roestenburg 的示例。
Intellij 项目是使用“Maven 模块”创建的,然后我将所有依赖项添加到并创建了我的项目。测试位于以下位置:
ActorBlast/src/test/scala/basicTest.scala
我基本上是“右键单击”测试并选择“运行”。我得到的是以下错误:
"C:\Program Files\Java\jdk1.7.0_25\bin\java" -Didea.launcher.port=7540... 测试于下午 2:29 开始... 无法加载套件类。这可能是由于您的运行路径中的错误。
缺少类:BasicActorSpec java.lang.ClassNotFoundException:在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:366) 在 java.security.AccessController 的 BasicActorSpec。 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) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) 在 org.scalatest.tools.Runner$$anonfun$35.apply(Runner.scala:2393) 在 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.收藏。TraversableLike$class.filter(TraversableLike.scala:263) at scala.collection.AbstractTraversable.filter(Traversable.scala:105) at org.scalatest.tools.Runner$.doRunRunDaDoRunRun(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) 在 org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:144) 在 org.jetbrains.plugins。scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:35) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl。 com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 的 java.lang.reflect.Method.invoke(Method.java:606) 的调用(DelegatingMethodAccessorImpl.java:43)execution.application.AppMain.main(AppMain.java:120)execution.application.AppMain.main(AppMain.java:120)
进程以退出代码 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
}
}
}
任何有关我为什么会收到此错误的帮助将不胜感激。