我遇到了一个问题,依赖项显然在测试之间流血,这导致大多数测试失败。在每种情况下,调试都会显示在测试类中创建的第一个应用程序用于所有测试,这会导致失败。
我试过添加isolated
,sequential
但这没有任何效果。
我是在做一些非常愚蠢或非常愚蠢的事情吗?
例如,这里的SubjectNotPresentTest.scala
class SubjectNotPresentTest extends AbstractViewTest {
"show constrained content when subject is not present" in new WithApplication(testApp(handler())) {
val html = subjectNotPresentContent(FakeRequest())
private val content: String = Helpers.contentAsString(html)
content must contain("This is before the constraint.")
content must contain("This is protected by the constraint.")
content must contain("This is after the constraint.")
}
"hide constrained content when subject is present" in new WithApplication(testApp(handler(subject = Some(user())))) {
val user = new User("foo", Scala.asJava(List.empty), Scala.asJava(List.empty))
val html = subjectNotPresentContent(FakeRequest())
private val content: String = Helpers.contentAsString(html)
content must contain("This is before the constraint.")
content must not contain("This is protected by the constraint.")
content must contain("This is after the constraint.")
}
}
GuiceApplicationBuilder 用于父类,用于创建应用程序进行测试。
val app = new GuiceApplicationBuilder()
.bindings(new DeadboltModule())
.bindings(bind[HandlerCache].toInstance(LightweightHandlerCache(handler)))
.overrides(bind[CacheApi].to[FakeCache])
.in(Mode.Test)
.build()
您可以在https://travis-ci.org/schaloner/deadbolt-2-scala/builds/66369307#L805查看失败示例
谢谢,史蒂夫