如何获得Spock注释关闭结果
问题描述:
我想知道如何获得IgnoreIf spock注释的布尔值。如何获得Spock注释关闭结果
举例来说,在我的剧本我可能有这样的事情:
@IgnoreIf({someBooleanMethod()})
def "Some Feature Method"(){
// code and stuff
}
我也有一个自定义的斯波克扩展。在extention我有这样的:
//iterates over each feature method in a spec
for (FeatureInfo feature : spec.getFeatures()){
if(feature.getFeatureMethod().reflection.isAnnotationPresent(IgnoreIf.class)&&feature.getFeatureMethod().reflection.getAnnotation(IgnoreIf.class).value()){
//some more code goes here
}
}
我要评价IgnoreIf闭合对包含IgnoreIf关闭每个功能的方法。如果我没有弄错,feature.getFeatureMethod().reflection.getAnnotation(IgnoreIf.class).value()
应该给我从给定的注释clouse,但我不知道如何实际评估我在闭合内有someBooleanMethod
,看看它是真的还是假的。我怎么做?
答
new IgnoreIfExtension().visitFeatureAnnotation(feature.getFeatureMethod().reflection.getAnnotation(IgnoreIf.class), feature)
这就是我所做的。如果IgnoreIf条件为真,它会将其设置为自己跳过
只需查看扩展的代码org.spockframework.runtime.extension.builtin.IgnoreIfExtension –
@LeonardBrünings我假设您指的是'evaluateCondition在那个班上找到的方法。它是一种非静态方法,所以如何获取该对象的实例以便我可以调用该方法 – switch201