【问题标题】:PlaySpec not found in IntelliJ在 IntelliJ 中找不到 PlaySpec
【发布时间】:2020-06-03 23:16:31
【问题描述】:

下面是 websocket 的 Scala 测试:

   import java.util.function.Consumer

import play.shaded.ahc.org.asynchttpclient.AsyncHttpClient
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.{Helpers, TestServer, WsTestClient}
import scala.compat.java8.FutureConverters
import scala.concurrent.Await
import scala.concurrent.duration._
import org.scalatestplus.play._

class SocketTest extends PlaySpec with ScalaFutures {

  "HomeController" should {

    "reject a websocket flow if the origin is set incorrectly" in WsTestClient.withClient { client =>

      // Pick a non standard port that will fail the (somewhat contrived) origin check...
      lazy val port: Int = 31337
      val app = new GuiceApplicationBuilder().build()
      Helpers.running(TestServer(port, app)) {
        val myPublicAddress = s"localhost:$port"
        val serverURL = s"ws://$myPublicAddress/ws"

        val asyncHttpClient: AsyncHttpClient = client.underlying[AsyncHttpClient]
        val webSocketClient = new WebSocketClient(asyncHttpClient)
        try {
          val origin = "ws://example.com/ws"
          val consumer: Consumer[String] = new Consumer[String] {
            override def accept(message: String): Unit = println(message)
          }
          val listener = new WebSocketClient.LoggingListener(consumer)
          val completionStage = webSocketClient.call(serverURL, origin, listener)
          val f = FutureConverters.toScala(completionStage)
          Await.result(f, atMost = 1000.millis)
          listener.getThrowable mustBe a[IllegalStateException]
        } catch {
          case e: IllegalStateException =>
            e mustBe an[IllegalStateException]

          case e: java.util.concurrent.ExecutionException =>
            val foo = e.getCause
            foo mustBe an[IllegalStateException]
        }
      }
    }

  }
}

但编译在import org.scalatestplus.play._ 行失败并出现错误:

Cannot resolve symbol scalatestplus

来自https://www.playframework.com/documentation/2.8.x/ScalaTestingWithScalaTest 我添加了scalatest 和play 来构建:

build.sbt:

name := "testproject"

version := "1.0" 

lazy val `testproject` = (project in file(".")).enablePlugins(PlayScala)

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"

resolvers += "Akka Snapshot Repository" at "https://repo.akka.io/snapshots/"

scalaVersion := "2.12.2"

libraryDependencies ++= Seq( jdbc , ehcache , ws  , guice , specs2 % Test)

// https://mvnrepository.com/artifact/com.typesafe.scala-logging/scala-logging
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"

libraryDependencies ++= Seq(
  "org.scalatestplus.play" %% "scalatestplus-play" % "3.0.0" % "test"
)
unmanagedResourceDirectories in Test <+=  baseDirectory ( _ /"target/web/public/test" )  

当我右键单击 build.sbt 时,我尝试在 IntelliJ“构建”选项和“构建选项”中重建项目和模块,但找不到导入。

【问题讨论】:

    标签: scala intellij-idea


    【解决方案1】:

    sbt dist 来自 Intellij "sbt shell" 然后是 File -> "Invalidate caches" 并重新启动 IntelliJ 似乎可以解决问题

    :Invalidate caches screenshot

    【讨论】:

      猜你喜欢
      • 2017-09-07
      • 2017-07-11
      • 2016-12-14
      • 1970-01-01
      • 2019-03-29
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多