【问题标题】:How to get Spock annotation closure result如何获得Spock注解闭包结果
【发布时间】:2017-10-19 14:02:58
【问题描述】:

我想知道如何获得 IgnoreIf spock 注释的布尔值。

例如在我的脚本中,我可能有这样的内容:

@IgnoreIf({someBooleanMethod()})
def "Some Feature Method"(){
    // code and stuff
}

我还有一个自定义 spock 扩展。在那个范围内,我有这个:

//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 以查看它是真还是假。我该怎么做?

【问题讨论】:

  • 只看Extension org.spockframework.runtime.extension.builtin.IgnoreIfExtension的代码
  • @Leonard Brünings 我假设您指的是该类中的evaluateCondition 方法。它是一个非静态方法,那么如何获取该对象的实例以便我可以调用该方法

标签: spock geb


【解决方案1】:

new IgnoreIfExtension().visitFeatureAnnotation(feature.getFeatureMethod().reflection.getAnnotation(IgnoreIf.class), feature)

这就是我所做的。如果 IgnoreIf 条件为真,它会将其设置为自行跳过

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 2012-04-02
    • 2019-11-06
    • 2014-04-25
    相关资源
    最近更新 更多