在我的pom.xml中使用这些依赖项
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-test-easymock-testng</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>1.5.5</version>
</dependency>
这是我的代码,其中Dispute是final类型。
@PrepareForTest(Dispute.class)
public void testProcessChargebackUpdates() {
final List<BraintreeGateway> credentials = new LinkedList<BraintreeGateway>();
credentials.add(credential);
// Dispute dispute = control.createMock(Dispute.class);
Dispute dispute = PowerMock.createMock(Dispute.class);
}
Gives无法实例化最终的课程。
答案 0 :(得分:1)
首先你需要这些依赖:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-test-easymock-testng</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<version>1.4.9</version>
</dependency><dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>1.5.5</version>
</dependency>
然后你需要在你的班级中使用@Prepare注释,并将最终的类作为嘲笑 以及要在类中定义的getObjectFactory方法。
@PrepareForTest(Dispute.class)
public void testProcessChargebackUpdates() {
@ObjectFactory
public IObjectFactory getObjectFactory() {
return new PowerMockObjectFactory();
}
}