Groovy 如何使用方法评估Spock@IgnoreIf
根据以下条款: 您应该能够使用静态方法计算Spock@IgnoreIf注释。我尝试了与本文中完全相同的isOsWindows()方法,得到了以下结果:Groovy 如何使用方法评估Spock@IgnoreIf,groovy,spock,Groovy,Spock,根据以下条款: 您应该能够使用静态方法计算Spock@IgnoreIf注释。我尝试了与本文中完全相同的isOsWindows()方法,得到了以下结果: org.spockframework.runtime.extension.ExtensionException: Failed to evaluate @IgnoreIf condition ... Caused by: groovy.lang.MissingMethodException: No signature of method: My
org.spockframework.runtime.extension.ExtensionException: Failed to evaluate @IgnoreIf condition
...
Caused by: groovy.lang.MissingMethodException: No signature of method: MySpec$__spock_feature_1_3_closure1.isOsWindows() is applicable for argument types: () values: []
有人对此有什么见解吗?我真的想根据规范设置一个真/假,我不需要其他示例中列出的任何os/系统属性
谢谢这个示例是用Spock 0.7-groovy-2编写的有点过时的
代码
,如果要使用静态方法,则需要使用限定版本的ClassName.method()
如果您只想在windows上运行,那么内置了一些方便的函数(Spock 1.+)
- 操作系统
@IgnoreIf({os.windows | | os.linux | | os.macOs | | os.solaris | | os.other})
- Java版本
@IgnoreIf({jvm.java5 | jvm.java6 | jvm.java7 | jvm.java8 | jvm.java9})
- 环境变量
@IgnoreIf({!env.containsKey(“FOOBARBAZ”)})
@IgnoreIf({env[“FOOBARBAZ”]=='false'})
- SystemProperty
@IgnoreIf({!sys.contains(“java.version”)})
@IgnoreIf({sys[“java.version”]=='1.6'})
package com.mrhaki.spock
import spock.lang.*
class SampleRequiresSpec extends Specification {
private static boolean isOsWindows() {
System.properties['os.name'] == 'windows'
}
@IgnoreIf({ SampleRequiresSpec.isOsWindows() })
def "run only if run on non-windows operating system"() {
expect:
true
}
}