我正在尝试使用 Betamax 在 Groovy 中使用 Spock 设置一个简单的测试:
class BetaMaxSpockTest extends Specification {
@Rule
public Recorder recorder = new Recorder()
@Betamax(tape = "some_tape")
def 'You shall pass'() {
expect:
true
}
}
我也在使用 Spring Boot,所以我在 pom.xml 中有 spring-boot-starter-parent 作为我的父级:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
</parent>
当我运行上面的测试时,我收到了这个错误:
java.lang.VerifyError: (class: co/freeside/betamax/proxy/jetty/BetamaxProxy, method: super$3$getBean signature: (Ljava/lang/Class;)Ljava/lang/Object;) Illegal use of nonvirtual function call
at java.lang.Class.forName(Class.java:264)
at co.freeside.betamax.proxy.jetty.ProxyServer.start(ProxyServer.groovy:47)
at co.freeside.betamax.Recorder.startProxy(Recorder.groovy:198)
at co.freeside.betamax.Recorder.withTape(Recorder.groovy:167)
at co.freeside.betamax.Recorder$1.evaluate(Recorder.groovy:185)
at org.spockframework.runtime.extension.builtin.MethodRuleInterceptor.intercept(MethodRuleInterceptor.java:40)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod
如果路径上没有 Spring Boot,它可以正常工作。看起来像一些版本问题。有人有类似的问题吗?
我的完整 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<!--plugins versions-->
<maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
<!--settings-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--Spring Boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--Spock Testing-->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<scope>test</scope>
</dependency>
<!--Groovy Testing-->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<scope>test</scope>
</dependency>
<!--Betamax Http Mocks-->
<dependency>
<groupId>co.freeside</groupId>
<artifactId>betamax</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<--...-->
</pluginManagement>
</build>
</project>