scala - 在 IntelliJ 中找不到 PlaySpec
问题描述
下面是 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 来构建:
构建.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“构建”选项和“构建选项”中重建项目和模块。
解决方案
sbt dist
从 Intellij “sbt shell” 然后 File -> “Invalidate caches” 重新启动 IntelliJ 似乎解决了这个问题
推荐阅读
- count - PowerBi Desktop:不同的度量缺失值
- javascript - 如何替换 javascript 标准内置对象?
- python - yaml.constructor.ConstructorError:在构建 Python 对象时,在模块“__main__”中找不到“module_name”
- solr - solr DateFormatTransporter
- r - 如何使用 R 中的 ggplot 绘制 x 中的向量和 y 中数据框的行?
- python - 如何将文本字符串插入到 ttk 条目中?[解决了]
- jdbc - 如果使用 setFetchSize 在 JDBC 中批量读取,如果我们对语句应用超时,那么它是批处理级别的超时吗?
- c# - 使用嵌入式文件(.exe 或 .msi)打包 dotnet 核心控制台应用程序
- reactjs - 给即将学习 reactjs 的开发者的材料建议
- arrays - Console.log 不匹配数组