specs2 无一例外地跳过基于条件的测试
specs2 skip test based on condition without an exception
有没有办法在不发生 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
这应该有效:
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
(或类似的东西,我没有 运行 代码)
有没有办法在不发生 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
这应该有效:
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
(或类似的东西,我没有 运行 代码)