我希望能够使用 JUnit 4.7预期异常@Rule http://kentbeck.github.com/junit/javadoc/latest/org/junit/rules/ExpectedException.html在斯卡拉。然而,它似乎没有捕捉到任何东西:
import org.junit._
class ExceptionsHappen {
@Rule
def thrown = rules.ExpectedException.none
@Test
def badInt: Unit = {
thrown.expect(classOf[NumberFormatException])
Integer.parseInt("one")
}
}
这仍然失败NumberFormatException
.
为了使其与 JUnit 4.11 一起工作in Scala,您应该对注释进行元注释,以便注释仅应用于(合成)getter 方法,而不是底层字段:
import org.junit._
import scala.annotation.meta.getter
class ExceptionsHappen {
@(Rule @getter)
var thrown = rules.ExpectedException.none
@Test
def badInt: Unit = {
thrown.expect(classOf[NumberFormatException])
Integer.parseInt("one")
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)