specs2 After 方法在示例之前运行 [英] specs2 After method runs before the example

查看:30
本文介绍了specs2 After 方法在示例之前运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下测试:

class Foo extends mutable.SpecificationWithJUnit {
sequential

"this example should run before the 'After' method" in new Context {
    bar must beSome
}

class Context extends mutable.BeforeAfter with mutable.Around {

  override def apply[T : AsResult](a: =>T): Result = {
  lazy val result = super[Around].apply(a)
  super[BeforeAfter].apply(result)
  }

  override def delayedInit(x: => Unit): Unit = around { try { before; x; Success() } finally { after }}

  @Resource var barReader : BarReader = _

  val bar = barReader.someBar

  override def before : Any = { //some stuff}

  def after: Any = {
    bar = None
  }

  override def around[T : AsResult](t: =>T) = {
     //spring context injection logic
     AsResult.effectively(t)
  }

  }
}
}

我希望这个测试能够通过,但实际上发生的情况是由于延迟的 init,之后在示例之前运行.如果我将 Context 更改为 trait,我将失去延迟的 init 功能.这是错误还是我做错了什么?

I expect this test to pass but in reality what happens is that because of the delayed init, the after runs before the example. If I change the Context to a trait I lose the delayed init functionality. Is this a bug or am I doing something wrong?

**当 Context 是 trait 时,此示例将抛出 NPE.我期望发生的是,由于延迟初始化,上下文的构造函数,这意味着 barReader.someBar 只会在 barReader 被注入后运行.

**Edited: This example will throw an NPE when the Context is a trait. What I expect to happen is that because of the delayed-init, the Context's constructor, which consequentially means the barReader.someBar will run only after the barReader has been injected.

谢谢内塔

推荐答案

简单的回答,貌似这个不行.

Simple answer, looks like this can't be done.

这篇关于specs2 After 方法在示例之前运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆