Mockito和PowerMockito的兼容
Mockito和PowerMockito的兼容
我的spring Boot是2.1.16RELEASE版本的,mockito是2.23.4版本的(这个版本的mockito去相应的powerMockito有点尴尬,啥也不是),junit是4.12版本的,直接复制百度与junit相应版本的powerMockito的依赖(如下)会报错:java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/Enhancer。
<!--powerMockito-->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
踩坑
查百度,有很多⽅法⽜头不对马嘴解决不了问题,主要有再加上cglib-nodep-2.1.3依赖的,byte-buddy和byte-buddy-agent依赖
的,mockito-all-2.0.2-beta依赖的。
会报这样的错
Could not initialize plugin: kito.plugins.MockMake
ptions.FieldNotFoundException: No instance field named "reporter" could be found in the class hierarchy kito.internal .MockitoCore.
java.lang.AbstractMethodError: org.kmaker.PowerMockMaker.isTypeMockable(Ljava/lang/Class;)Lorg/mockito/plugins /MockMaker$TypeMockability;
等等。。。
弃坑
⽤java.lang.AbstractMethodError: org.kmaker.PowerMockMaker.isTypeMockablespringboot是啥
这个错误去百度了下,然后就到了解决办法如下。
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>2.0.0-RC.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>    <version>2.0.0-beta.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>    <version>2.0.0-beta.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.9</version>
</dependency>
<dependency>
<groupId&kito</groupId>
<artifactId>mockito-inline</artifactId>
<version>2.15.0</version>
</dependency>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。