我使用Spock Framework编写单元测试,并在将@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.
这里是我添加的Maven依赖:
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4</version>
<scope>test</scope>
</dependency>
这是测试中的虚拟单元:
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;
}
}
这是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")
}
}
任何人都可以解释错误和/或指出可能的问题吗?提前谢谢。