Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使TestExecutionListener跳过/忽略测试_Spring_Junit - Fatal编程技术网

Spring 使TestExecutionListener跳过/忽略测试

Spring 使TestExecutionListener跳过/忽略测试,spring,junit,Spring,Junit,我目前正在使用SpringTestExecutionListener来处理测试类中的自定义注释。取决于一些外部环境,我想忽略一个测试 目前,我正在使用beforeTestClass或beforeTestMethod中的一个假设来实现这一点,这很有效。但不幸的是,它在日志中创建了一个警告,其中包括一个远离噪音的堆栈跟踪 是否有可能以编程方式忽略测试(可能使用TestContext)?我认为您可以尝试扩展默认的测试运行程序,并提供isIgnored方法的自定义实现: public class Cus

我目前正在使用SpringTestExecutionListener来处理测试类中的自定义注释。取决于一些外部环境,我想忽略一个测试

目前,我正在使用
beforeTestClass
beforeTestMethod
中的一个假设来实现这一点,这很有效。但不幸的是,它在日志中创建了一个警告,其中包括一个远离噪音的堆栈跟踪


是否有可能以编程方式忽略测试(可能使用TestContext)?

我认为您可以尝试扩展默认的测试运行程序,并提供
isIgnored
方法的自定义实现:

public class CustomRunner extends BlockJUnit4ClassRunner {
    public CustomRunner(Class<?> c) throws initializationError {
        super(c);
    }

    @Override
    protected boolean isIgnored(FrameworkMethod child) {
        if(shouldIgnore()) {
           return true;
        }
        return super.isIgnored(child);
    }

    private boolean shouldIgnore() {
        /* some custom criteria */
    }
}
公共类CustomRunner扩展了BlockJUnit4ClassRunner{
公共CustomRunner(c类)引发初始化错误{
超级(c);
}
@凌驾
受保护的布尔值isIgnored(FrameworkMethod子级){
if(shouldIgnore()){
返回true;
}
返回super.isIgnored(子级);
}
私有布尔shouldIgnore(){
/*一些自定义标准*/
}
}

这里,忽略带有
@Ignore
注释的测试,但您可以提供自己的忽略条件实现。

我认为您可以尝试扩展默认测试运行程序,并提供
isIgnored
方法的自定义实现:

public class CustomRunner extends BlockJUnit4ClassRunner {
    public CustomRunner(Class<?> c) throws initializationError {
        super(c);
    }

    @Override
    protected boolean isIgnored(FrameworkMethod child) {
        if(shouldIgnore()) {
           return true;
        }
        return super.isIgnored(child);
    }

    private boolean shouldIgnore() {
        /* some custom criteria */
    }
}
公共类CustomRunner扩展了BlockJUnit4ClassRunner{
公共CustomRunner(c类)引发初始化错误{
超级(c);
}
@凌驾
受保护的布尔值isIgnored(FrameworkMethod子级){
if(shouldIgnore()){
返回true;
}
返回super.isIgnored(子级);
}
私有布尔shouldIgnore(){
/*一些自定义标准*/
}
}

这里,忽略具有
@Ignore
注释的测试,但是您可以提供自己的忽略条件实现。

您不能只添加
@ActiveProfiles(profiles={“dev”}
用于测试和关闭配置文件?由于复杂的硬件要求,不进行复杂的测试是不可能的。因此,我们创建了自己的注释来跳过测试,具体取决于连接的设备。您不能添加
@ActiveProfiles(profiles={“dev”}
对于测试和开关配置文件?由于复杂的硬件要求,如果没有复杂的硬件要求是不可能的。因此,我们创建了自己的注释,以根据连接的设备跳过测试