2
specs2를 사용하여 단위 테스트 케이스를 작성하고 각 테스트 인스턴스에 대해 내 응용 프로그램을 시작하고 중지했습니다.spec2 스칼라 테스트에서 OneAppPerSuite 대체
import org.specs2.mutable._
class HelloWorldSpec extends Specification {
"The 'Hello world' string" should {
"contain 11 characters" in new WithApplication {
"Hello world" must have size(11)
}
"start with 'Hello'" in new WithApplication {
"Hello world" must startWith("Hello")
}
"end with 'world'" in new WithApplication {
"Hello world" must endWith("world")
}
}
}
각 테스트 사례에 대한 설명서에서 언급 한대로 응용 프로그램이 시작되고 중지됩니다.
link에서 해결 방법을 발견했습니다. 응용 프로그램은 각 테스트 클래스에 대해 한 번만 초기화됩니다 (아직 테스트하지 않았습니다).
import org.specs2.mutable._
class HelloWorldSpec extends Specification {sequential
step(Play.start(App)) //supposedly App is iniatilized
"The 'Hello world' string" should {
"contain 11 characters" in {
"Hello world" must have size(11)
}
"start with 'Hello'" in {
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
"Hello world" must endWith("world")
}
}
step(Play.stop())
}
하지만 여러 개의 클래스가 있고 앱을 한 번 시작하고 중지하려면 어떻게해야합니까?
한 번만 앱을 시작하고 중지하려면 어떻게해야합니까?
OneAppPerSuite
을 사용하여 scalatest
에 구현 된 유사한 솔루션이 있습니다. 여기에 link 및 예가 나와 있습니다.
import play.api.test._
import org.scalatest._
import org.scalatestplus.play._
import play.api.{Play, Application}
import play.api.inject.guice._
// This is the "master" suite
class NestedExampleSpec extends Suites(
new OneSpec,
new TwoSpec,
new RedSpec,
new BlueSpec
) with OneAppPerSuite {
// Override app if you need an Application with other than non-default parameters.
implicit override lazy val app: Application =
new GuiceApplicationBuilder().configure(Map("ehcacheplugin" -> "disabled")).build()
}
// These are the nested suites
@DoNotDiscover class OneSpec extends PlaySpec with ConfiguredApp
@DoNotDiscover class TwoSpec extends PlaySpec with ConfiguredApp
@DoNotDiscover class RedSpec extends PlaySpec with ConfiguredApp
@DoNotDiscover
class BlueSpec extends PlaySpec with ConfiguredApp {
"The OneAppPerSuite trait" must {
"provide an Application" in {
app.configuration.getString("ehcacheplugin") mustBe Some("disabled")
}
"make the Application available implicitly" in {
def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key)
getConfig("ehcacheplugin") mustBe Some("disabled")
}
"start the Application" in {
Play.maybeApplication mustBe Some(app)
}
}
}
specs2에서 비슷한 것을 구현할 수 있습니까? 당신이 specification references와 비슷한 뭔가를 할 수 specs2와
감사합니다 대답을 위해 비슷한 솔루션을 구현하려고했지만 BeforeAfterA를 사용했습니다. 앱을 시작하고 중지 할 수 있습니다. 하지만 앱이 시작되기 전에 연결된 클래스가 먼저 실행되기 때문에 문제가있었습니다. – perfectus