我正在将Spock与Geb结合用于网络浏览器测试。
我创建了" stepThrough"按照此处的说明进行扩展:
Spock Stepwise - Keep running testsuite after single failure
这一切都很好,但我想做一个新的注释。这为#34; Mandatory"设置了一个geb特征方法。这意味着如果这个特征方法失败,我想停止执行剩下的测试。
我喜欢stepThrough注释,因为如果一个测试用例失败,我可以继续我的其余测试,但如果登录失败,那么我会想要停止测试,因为如果登录失败,显然没有别的办法可以工作。 / p>
这就是我所拥有的,但它似乎没有起作用。我哪里出错?
这是Annotation类 import org.spockframework.runtime.extension.ExtensionAnnotation
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@ExtensionAnnotation(ManditoryExtension.class)
@interface Manditory {}
这是扩展名:
class ManditoryExtension extends AbstractAnnotationDrivenExtension<Manditory>{
void visitFeatureAnnotation(Manditory annotation, FeatureInfo feature) {
skipFeaturesAfterFirstFailingFeature(feature)
}
private void skipFeaturesAfterFirstFailingFeature(final FeatureInfo feature){
feature.getParent().getBottomSpec().addListener(new AbstractRunListener() {
void error(ErrorInfo error) {
if (!error.getMethod().equals(feature)) return
for (FeatureInfo feat : feature.getSpec().getFeatures())
feat.setSkipped(true)
}
})
}
}