Spock Stepwise - 单次故障后继续运行测试套件

时间:2015-06-22 09:59:53

标签: spring grails spock geb

使用Spock @Stepwise注释时,有没有办法将其配置为在单个测试失败后不会使整个测试套件失败?

1 个答案:

答案 0 :(得分:4)

决定只创建一个名为@StepThrough的新扩展。我需要做的只是继承StepwiseExtension,并取出整个测试套件失败的代码行。贴下面的代码......

StepThrough.groovy

package com.test.SpockExtensions

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

/**
 * Created by jchertkov on 6/22/15.
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ExtensionAnnotation(StepThroughExtension.class)
public @interface StepThrough {}

StepThroughExtension.groovy

package com.test.SpockExtensions

import org.spockframework.runtime.extension.builtin.StepwiseExtension
import org.spockframework.runtime.model.SpecInfo

import java.lang.annotation.Annotation

/**
 * Created by jchertkov on 6/22/15.
 */
public class StepThroughExtension extends StepwiseExtension {
    public void visitSpecAnnotation(Annotation annotation, final SpecInfo spec) {
        sortFeaturesInDeclarationOrder(spec);
        includeFeaturesBeforeLastIncludedFeature(spec);
    }
}

注意:

  • 我将代码放入一个名为com.test.SpockExtensions的包中。你需要用你想要的任何名字做同样的事情。
  • Java用户 - 只需将文件类型从.groovy更改为.java