Powermockito对java代码可以进行静态方法的Mock. 用于junit单元测试, 但由于依赖问题, 在运行Junit时候, 会遇到Initialization error
一般见于Powermockito <1.6.1的版本和Junit<4.12的版本.
解决方法: maven中修改依赖为:

<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-api-mockito</artifactId>
  <version>1.6.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-module-junit4</artifactId>
  <version>1.6.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>

即可

参考:

http://stackoverflow.com/questions/26192929/unable-to-run-junit-test-with-powermockrunner

标签: none 阅读量: 1583

添加新评论