ScalaTest WordSpec允许测试像这样被忽略:ScalaTest:有条件地忽略WordSpec测试
class MySpec extends WordSpec {
"spec" should {
"ignore test" ignore {fail("test should not have run!")}
}
}
这是伟大的,但我并不想了解被忽略的测试给忘了。所以我希望忽略行为在提供日期后过期。在这一点上,测试将像平常一样运行,并且:1)通过(希望)或2)提醒我它仍然被破坏。
为了实现这一点,我试图扩展WordSpec DSL以支持ignoreUntil
函数。这将接受字符串失效日期,如果日期仍然未来,则忽略测试,否则运行测试。然后
我的测试规范会是什么样子:
class MySpec extends EnhancedWordSpec {
"spec" should {
"conditionally ignore test" ignoreUntil("2099-12-31") {fail("test should not have run until the next century!")}
}
}
我已经实现了ignoreUntil
功能在这里:
class EnhancedWordSpec extends WordSpecLike {
implicit protected def convertToIgnoreUntilWrapper(s: String) = new IgnoreUntilWordSpecStringWrapper(s)
protected final class IgnoreUntilWordSpecStringWrapper(wrapped: String) {
// Run test or ignore, depending if expiryDate is in the future
def ignoreUntil(expiryDate: String)(test: => Any): Unit = ???
}
}
然而sbt test
给了我下面的编译错误:
MySpec.scala:3: type mismatch;
[error] found : Char
[error] required: String
[error] "ignoreUntil" ignoreUntil("2099-12-31"){fail("ignoreUntil should not have run!")}
[error] ^
[error] one error found
[error] (test:compileIncremental) Compilation failed
为什么编译器不喜欢的签名功能?
是否有一些巫术与暗示进行?
我已经考虑了单个参数集和折扣,因为它改变了测试多一点,比我想的结构。 但我喜欢你在调用'ignoreUntil'时使用显式点字符的解决方案。这对我来说似乎是一个不太干扰的修复。 感谢您解释错误并提出解决方案。 – cybersaurus