1 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊
最簡(jiǎn)單的方法如下:
定義一個(gè)自定義注釋,使用時(shí)聲明需要跳過特定測(cè)試方法的配置。
@Test
使用這個(gè)新注釋注釋要跳過配置的所有方法。在您的配置方法中,檢查傳入方法是否具有此注釋,如果是,則跳過執(zhí)行。
下面是一個(gè)示例,顯示了所有這些操作。
指示要跳過配置方法的標(biāo)記注釋。
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target({METHOD, TYPE})
public @interface SkipConfiguration {
}
樣本測(cè)試類
import java.lang.reflect.Method;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class TestClassSample {
@Test
@SkipConfiguration
public void foo() {}
@Test
public void bar() {}
@AfterMethod
public void teardown(Method method) {
SkipConfiguration skip = method.getAnnotation(SkipConfiguration.class);
if (skip != null) {
System.err.println("Skipping tear down for " + method.getName());
return;
}
System.err.println("Running tear down for " + method.getName());
}
}
添加回答
舉報(bào)