有没有办法在没有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中有以下内容时,我无法编译上面的代码片段。
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
答案 0 :(得分:1)
这应该有效:
class Skipped extends Specification{
"Application" should {
if( 3 < 2 ){
"do better with regex" in {
"axbcd" must find( "bc".r )
}
}
else "3 is >= 2" in skipped( "blah" )
}
}
区别在于skipped
在示例的正文中声明,允许将其报告给控制台:
[info] o 3 is >= 2
[info] SKIPPED blah
(或类似的东西,我没有运行代码)