will-gilbert / spock-powermock Goto Github PK
View Code? Open in Web Editor NEWUsing the Spock Framework with PowerMock
Using the Spock Framework with PowerMock
Hi,
So I have a Java project, and I'm using Spock + Powermock for writing Unit Tests. I have some tests which are fully written using Spock, and some which use Spock + Powermock. I use Powermock to test static methods. My usage of powermock is as below:
@RunWith(PowerMockRunner)
@PowerMockRunnerDelegate(Sputnik)
@PrepareForTest([class1,class2])
class Test extends Specification {
def "test 1"(){
setup:
mockstatic(class1)
class1 obj = mock(class1.class)
...
...
}
}
The gradle configuration which I used is :
// spock
testCompile "org.spockframework:spock-core:1.2-groovy-2.5"
//junit
testCompile 'junit:junit:4.12'
// mock
testRuntime 'cglib:cglib-nodep:3.2.6'
testRuntime 'org.objenesis:objenesis:2.6'
//mockito
testCompile 'org.mockito:mockito-core:2.9.0'
// Power mock
testCompile 'org.powermock:powermock-api-mockito2:1.7.3'
testCompile 'org.powermock:powermock-module-junit4:1.7.3'
When I run my test-suite, the Spock + Powermock TC's pass, but those using only Spock fail, with error message as below:
Could not create type
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.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:58)
at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:38)
at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:42)
at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:46)
at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:294)
at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:284)
at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:84)
at com.samsung.iotcloud.bixbyhint.clients.location.implementations.LocationServiceImplTest.LocationServiceImpl getLocations should return proper response(LocationServiceImplTest.groovy:29)
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)
... 13 more
I am stuck with this problem since a week and would greatly appreciate any fix.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.