我正在使用SpringBoot 1.5.9,Groovy 2.4.13,Spock-core-1.2-groovy-2.4和Spock-Spring-1.2-groovy-2.4。 我尝试按照文档和Internet上的一些教程进行操作:
下面您可以看到我的测试代码的版本。
第一个版本:
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
import spock.lang.Unroll
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@SpringBootTest
@AutoConfigureMockMvc
class NotaFiscalControllerIT extends Specification {
@Unroll
def "NotaFiscalController::webhook => falha -> Token #cenario" () {
given:
notaFiscalService.processarRetornoWebhook(_ as DadoRetornadoDto) >> null
when:
def result = this.mvc.perform(
get('/webhook')
.header('sec-token', token)
.contentType(MediaType.APPLICATION_JSON)
)
then:
result.andExpect(status().isUnauthorized())
where:
cenario | token
'ausente' | ''
'inválido' | 'blablebli'
}
/**********************************************************************/
@Autowired
MockMvc mvc
@SpringBean
NotaFiscalService notaFiscalService = Mock()
/**********************************************************************/
}
第二版:
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
import spock.lang.Unroll
import spock.mock.DetachedMockFactory
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@WebMvcTest(controllers = [NotaFiscalController])
class NotaFiscalControllerIT extends Specification {
@Unroll
def "NotaFiscalController::webhook => falha -> Token #cenario" () {
given:
notaFiscalService.processarRetornoWebhook(_ as DadoRetornadoDto) >> null
when:
def result = this.mvc.perform(
get('/webhook')
.header('sec-token', token)
.contentType(MediaType.APPLICATION_JSON)
)
then:
result.andExpect(status().isUnauthorized())
where:
cenario | token
'ausente' | ''
'inválido' | 'blablebli'
}
/**********************************************************************/
@Autowired
MockMvc mvc
@Autowired
NotaFiscalService notaFiscalService
/**********************************************************************/
@TestConfiguration
static class MockConfig {
def detachedMockFactory = new DetachedMockFactory()
@Bean
NotaFiscalService notaFiscalService() {
return detachedMockFactory.Mock(NotaFiscalService)
}
}
}
无论我做什么,我总是会遇到相同的异常:
2019-02-06 11:24:09.184 ERROR 6266 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) ~[byte-buddy-1.6.14.jar:na]
at org.spockframework.mock.runtime.ByteBuddyMockFactory.createMock(ByteBuddyMockFactory.java:41) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:42) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockSpringProxyCreator.create(SpockSpringProxyCreator.java:29) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockDefinition.createMock(SpockDefinition.java:75) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.createMock(SpockMockPostprocessor.java:140) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.registerMock(SpockMockPostprocessor.java:108) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.register(SpockMockPostprocessor.java:92) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:85) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:78) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:171) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) [spring-boot-test-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) [spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:56) [spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.SpringInterceptor.interceptInitializerMethod(SpringInterceptor.java:43) [spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:24) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:97) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:475) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runInitializer(BaseSpecRunner.java:341) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runInitializer(BaseSpecRunner.java:336) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:274) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.ParameterizedSpecRunner.runIterations(ParameterizedSpecRunner.java:139) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.ParameterizedSpecRunner.runParameterizedFeature(ParameterizedSpecRunner.java:41) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:259) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:243) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:484) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:467) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:235) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:185) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:95) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:81) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:484) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:467) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:73) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:64) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.Sputnik.run(Sputnik.java:63) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) [junit-rt.jar:na]
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup.isAvailable()Z
at org.spockframework.mock.runtime.ByteBuddyMockFactory.determineBestClassLoadingStrategy(ByteBuddyMockFactory.java:103) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory.access$300(ByteBuddyMockFactory.java:27) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:54) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:43) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) ~[byte-buddy-1.6.14.jar:na]
... 54 common frames omitted
2019-02-06 11:24:09.187 INFO 6266 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@36f7d7b: startup date [Wed Feb 06 11:24:06 BRST 2019]; root of context hierarchy
2019-02-06 11:24:09.191 ERROR 6266 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@670002] to prepare test instance [br.com.k21.notafiscal.controller.NotaFiscalControllerIT@283ab206]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:56) [spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.SpringInterceptor.interceptInitializerMethod(SpringInterceptor.java:43) [spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:24) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:97) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:475) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runInitializer(BaseSpecRunner.java:341) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runInitializer(BaseSpecRunner.java:336) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:274) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.ParameterizedSpecRunner.runIterations(ParameterizedSpecRunner.java:139) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.ParameterizedSpecRunner.runParameterizedFeature(ParameterizedSpecRunner.java:41) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:259) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:243) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:484) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:467) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:235) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:185) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:95) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:81) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:484) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:467) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:73) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:64) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.runtime.Sputnik.run(Sputnik.java:63) [spock-core-1.2-groovy-2.4.jar:1.2]
at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.12.jar:4.12]
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) [junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) [junit-rt.jar:na]
Caused by: java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161) ~[byte-buddy-1.6.14.jar:na]
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355) ~[byte-buddy-1.6.14.jar:na]
at org.spockframework.mock.runtime.ByteBuddyMockFactory.createMock(ByteBuddyMockFactory.java:41) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:42) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockSpringProxyCreator.create(SpockSpringProxyCreator.java:29) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockDefinition.createMock(SpockDefinition.java:75) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.createMock(SpockMockPostprocessor.java:140) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.registerMock(SpockMockPostprocessor.java:108) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.register(SpockMockPostprocessor.java:92) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:85) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:78) ~[spock-spring-1.2-groovy-2.4.jar:1.2]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:171) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120) ~[spring-boot-test-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) ~[spring-test-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 32 common frames omitted
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup.isAvailable()Z
at org.spockframework.mock.runtime.ByteBuddyMockFactory.determineBestClassLoadingStrategy(ByteBuddyMockFactory.java:103) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory.access$300(ByteBuddyMockFactory.java:27) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:54) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:43) ~[spock-core-1.2-groovy-2.4.jar:1.2]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138) ~[byte-buddy-1.6.14.jar:na]
... 54 common frames omitted
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.spockframework.spring.SpringTestContextManager.prepareTestInstance(SpringTestContextManager.java:56)
at org.spockframework.spring.SpringInterceptor.interceptInitializerMethod(SpringInterceptor.java:43)
at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:24)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:97)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
at org.spockframework.mock.runtime.ByteBuddyMockFactory.createMock(ByteBuddyMockFactory.java:41)
at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:42)
at org.spockframework.spring.mock.SpockSpringProxyCreator.create(SpockSpringProxyCreator.java:29)
at org.spockframework.spring.mock.SpockDefinition.createMock(SpockDefinition.java:75)
at org.spockframework.spring.mock.SpockMockPostprocessor.createMock(SpockMockPostprocessor.java:140)
at org.spockframework.spring.mock.SpockMockPostprocessor.registerMock(SpockMockPostprocessor.java:108)
at org.spockframework.spring.mock.SpockMockPostprocessor.register(SpockMockPostprocessor.java:92)
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:85)
at org.spockframework.spring.mock.SpockMockPostprocessor.postProcessBeanFactory(SpockMockPostprocessor.java:78)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:171)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 13 more
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup.isAvailable()Z
at org.spockframework.mock.runtime.ByteBuddyMockFactory.determineBestClassLoadingStrategy(ByteBuddyMockFactory.java:103)
at org.spockframework.mock.runtime.ByteBuddyMockFactory.access$300(ByteBuddyMockFactory.java:27)
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:54)
at org.spockframework.mock.runtime.ByteBuddyMockFactory$1.call(ByteBuddyMockFactory.java:43)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
... 35 more
Process finished with exit code 255
我在做什么错了?
答案 0 :(得分:1)
我实际上没有检查过您的代码,但是我注意到您的日志中有byte-buddy-1.6.14.jar
。如果您使用Spock 1.1或1.2,也许您想根据this answer升级ByteBuddy版本:
spock-core:1.2-groovy-2.4
=> byte-buddy:1.8.21
spock-core:1.1-groovy-2.4
=> byte-buddy:1.6.5
感谢Szymon Stepniak发表了我链接到的答案。