1

我目前正在使用新的 Adob​​e Flex 4.8 构建 Flexmojos 项目。问题是,在 4.8 中,一项功能不再可用。如果我针对这个 sdk 运行单元测试,构建将失败。我可以一起禁用失败的测试,但我想保留它们,因为它们测试旧 Flex SDK 的重要特性。

如果不满足前提条件,有没有办法自动跳过测试?我正在考虑调用一些方法来决定是否应该执行测试。或者,我可以设置一个环境变量。如果有任何其他选择,我会很高兴听到。

克里斯

4

1 回答 1

3

One way i can think of doing this in testNg is by using IAnnotationTransformer listener. Basically you can manipulate the annotation in runtime. here is an example:

Listener:

public class SampleAnnotationTransformer implements IAnnotationTransformer {

@Override
public void transform(ITestAnnotation iTestAnnotation, Class aClass, Constructor constructor, Method method) {

    if(method != null){
        if(!isThisTestCompatible(method)){
            //diable the test case.
            iTestAnnotation.setEnabled(false);
        }
    }

}

private boolean isThisTestCompatible(Method method){
    //your logic goes here...
    return false;
}
}

configure above listener in testNG as shown below:

<suite name="Suit" verbose="1">
<listeners>
    <listener class-name="SampleAnnotationTransformer" />
</listeners>

//test cases...

Worth checking other listeners as well at http://testng.org/doc/documentation-main.html#testng-listeners

于 2012-11-01T14:19:13.540 回答