Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
Java Groovy@TypeChecked错误_Java_Groovy_Spock - Fatal编程技术网

Java Groovy@TypeChecked错误

Java Groovy@TypeChecked错误,java,groovy,spock,Java,Groovy,Spock,我正在使用Spock框架编写单元测试,在将@TypeChecked添加到测试类时遇到以下错误: Error:(16, 9) Groovyc: [Static type checking] - Cannot find matching method org.spockframework.runtime.SpockRuntime#verifyMethodCondition(org.spockframework.runtime.ErrorCollector, org.spockframework.ru

我正在使用Spock框架编写单元测试,在将@TypeChecked添加到测试类时遇到以下错误:

Error:(16, 9) Groovyc: [Static type checking] - Cannot find matching method org.spockframework.runtime.SpockRuntime#verifyMethodCondition(org.spockframework.runtime.ErrorCollector, org.spockframework.runtime.ValueRecorder, java.lang.String, java.lang.Integer, java.lang.Integer, <unknown parameter type>, java.lang.Object, java.lang.Object, java.lang.Object[], java.lang.Object, java.lang.Boolean, java.lang.Integer). Please check if the declared type is right and if the method exists.
错误:(16,9)Groovyc:[静态类型检查]-找不到匹配的方法org.spockframework.runtime.SpockRuntime#verifyMethodCondition(org.spockframework.runtime.ErrorCollector,org.spockframework.runtime.ValueRecorder,java.lang.String,java.lang.Integer,java.lang.Object,java.lang.Object,java.lang.Object[],java.lang.Object,java.lang.Boolean,java.lang.Integer)。请检查声明的类型是否正确以及方法是否存在。
下面是我要添加的Maven依赖项:

    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.1-groovy-2.4</version>
        <scope>test</scope>
    </dependency>

org.spockframework
斯波克堆芯
1.1-groovy-2.4
测试
这是正在测试的虚拟单元:

import java.util.ArrayList;
import java.util.List;

    public class TypeCheckedIssue {
        public List<String> getList() {
            List<String> list = new ArrayList<String>();
            list.add("hello");
            list.add("goodbye");
            return list;
        }
    }
import java.util.ArrayList;
导入java.util.List;
公共类类型检查问题{
公共列表getList(){
列表=新的ArrayList();
添加(“你好”);
列表。添加(“再见”);
退货清单;
}
}
下面是Groovy中的Spock测试:

import groovy.transform.TypeChecked
import spock.lang.Specification

@TypeChecked
class TypeCheckedIssueTest extends Specification {
    def "determine if exists in collection"() {
        given:
        TypeCheckedIssue typeCheckedIssue = new TypeCheckedIssue()

        when:
        List<String> result = typeCheckedIssue.getList()

        then:
        result.contains("hello")
    }
}
导入groovy.transform.TypeChecked
导入spock.lang.Specification
@打字检查
类TypeCheckedAssueTest扩展了规范{
def“确定集合中是否存在”(){
鉴于:
TypeCheckedIssue TypeCheckedIssue=新的TypeCheckedIssue()
什么时候:
列表结果=typeCheckedIssue.getList()
然后:
result.contains(“hello”)
}
}

有人能解释错误和/或指出可能的问题吗?提前谢谢。

为什么需要检查测试类型?我建议对测试中的代码进行类型检查,而不是测试本身。斯波克非常有活力,在引擎盖下使用了很多AST。。。不确定它是否真的与TypeChecked兼容。为什么需要对测试进行TypeChecked?我建议对测试中的代码进行类型检查,而不是测试本身。斯波克非常有活力,在引擎盖下使用了很多AST。。。不确定它是否真的与TypeChecked兼容。