【发布时间】:2015-05-27 14:22:21
【问题描述】:
有没有办法在不发生 SkippedException 的情况下跳过 specs2 中的测试?我希望测试在特定条件下被忽略,这样它就不会显示为错误而是被忽略。 例如:我在 test/scala/Skipped.scala 文件中有以下内容
package models
import org.specs2.mutable._
import org.specs2.runner._
class Skipped extends Specification{
"Application" should {
if( 3 < 2 ){
"do better with regex" in {
"axbcd" must find( "bc".r )
}
}
else skipped( "blah" )
}
}
以下是我的 build.sbt
scalaVersion := "2.10.3"
libraryDependencies += "org.specs2" % "specs2_2.10" % "2.1.1" % "test"
当我运行测试时,我得到以下信息:
org.specs2.execute.SkipException: blah
at org.specs2.matcher.ThrownExpectations$class.skipped(ThrownExpectations.scala:87)
我错过了什么吗?
奖金问题: 为什么我用这么旧的版本?当我的 build.sbt 中有以下内容时,我无法编译上面的代码 sn-p。
scalaVersion := "2.11.1"
libraryDependencies += "org.specs2" %% "specs2" % "2.3.12" % "test"
错误是:
Skipped.scala:7: overloaded method value should with alternatives:
[error] (fs: => Unit)(implicit p1: Skipped.this.ImplicitParam1, implicit p2: Skipped.this.ImplicitParam2)org.specs2.specification.Fragments <and>
[error] (fs: => org.specs2.specification.Fragments)(implicit p: Skipped.this.ImplicitParam)org.specs2.specification.Fragments <and>
[error] (fs: => org.specs2.specification.Fragment)org.specs2.specification.Fragments
[error] cannot be applied to (Product with Serializable)
[error] "Application" should {
[error] ^
[error] one error found
如果有人可以帮助我无一例外地跳过测试,我将不胜感激,这最好适用于新版本的 specs2
【问题讨论】:
标签: specs2