当前位置: 首页 > 知识库问答 >
问题:

在IntelliJ中运行ScalaTest时“无法加载套件类”

呼延晋
2023-03-14

我今天在IntelliJ中运行一个简单的TestKit测试时遇到了一些问题。测试是针对Scala代码的(我有用于Intellij的Scala插件),并且基于Ray Roestenburg的示例。

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

缺少类: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(本机方法)at java.net.URLClassLoader.findClass(URLClassLoader.java:354)at.scalatest.tools.runner$$anonfun$35.在org.scalatest.tools.runner$$$anonfun$35.在scala.collection.traversablelike$$$anonfun$1应用(runner.scala:2391)在scala.collection.traversablelike.$$anonfun$filter$1应用(runner.scala:2391)在scala.collection.immutable.list.foreach(list.scalction.traversablelike$class.filter在o处运行(runner.scala:2391)rg.scalatest.tools.runn$$anonfun$runoptionallyWithPassfailReporter$2.在org.scalatest.tools.runn$$anonfun$runoptionallyWithPassfailReporter$2.在org.scalatest.tools.runn.$$anonfun$runoptionallyWithPassfailReporter$2.在org.scalatest.tools.runner应用(runner.scala:1006)在org.scalatest.tools.runner应用gins.scala.testingsupport.scalatest.scalatestrunner.runscalateStrunner.java:144)在org.jetbrains.plugins.scala.testingsupport.scalatingsupport.scalatestrunner.main(scalateStrunner.java:35)在sun.reflect.nativeMethodAccessorImpl.invoke0(原生方法)在sun.reflect.nativeMethodAccessorImpl.invoke(com.intellij.rt.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
    }
  }

}

任何关于为什么我会得到这个错误的帮助都将非常感谢。

共有1个答案

蒙经纶
2023-03-14

运行build the Project--它帮助我解决了在试图解决另一个问题时清除缓存想法时可能发生的问题:)

 类似资料:
  • 我无法在eclipse中使用testNG for Selenium2运行测试套件。TestNG似乎正在运行,但运行的测试总数始终为0。我可以直接使用selenium2从eclipse运行这个测试(以->Java应用程序运行)。我可以用@test、@beforeMethod、@afterMethod注释测试一个小程序的testNG

  • null 我的代码是: 我尝试过创建Scala工作表,它工作了。

  • 我用intelliJ创建了一个简单的Spring Boot Web应用程序。我放置了一个简单的。jsp文件位于/src/main/resources/templates/文件夹中,其中包含一些基本的HTML。 我试图在控制器中返回这个,但我得到了这个错误; 我假设Spring找不到。jsp文件,但控制台中没有出现其他错误来提供任何进一步的信息。 这是我的简单控制器; 我的申请表中包括了以下内容。财

  • 我将感谢任何帮助,我可以得到以下问题。 所以当我从浏览器运行项目时,一切都很好。我可以使用AMQPConnection等。但是从终端运行时,它找不到AMQPConnection类。 在我的composer.json中,我还安装了amqplib 我使用Docker,Dockerfile包含: 更新!我已经打印了phpinfo(),当发送消息时,我有版本7.2.8,当执行终端命令时,我有版本7.2.7

  • 我有以下项目结构 我的文件夹在Intellij中标记为。

  • log4j:警告请正确初始化log4j系统。 log4j:警告有关更多信息,请参见http://logging.apache.org/log4j/1.2/faq.html#noconfig。