我遇到了依赖关系问题,显然在测试之间出血,导致大多数测试失败。在每种情况下,调试都会显示在测试类中创建的第一个应用程序用于所有测试,这会导致失败。Play中的Specs2/Guice问题2.4.0功能测试
我试过添加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在parent class使用用于创建用于测试的应用程序。
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
看到失败的例子所有的测试可以在https://github.com/schaloner/deadbolt-2-scala/tree/master/code/test/be/objectify/deadbolt/scala/views找到
感谢, 史蒂夫