2015-07-11 26 views
2
I am trying to mock the static method of CouchbaseCluster.create() using powermockito. Here is my test class. 

@PrepareForTest(CouchbaseCluster.class) 
public class IAMKafkaConsumerTest extends PowerMockTestCase{ 

    private IAMKafkaConsumer iamKafkaConsumer; 
    private CouchbaseCluster mockCouchbaseCluster; 
    private Bucket mockBucket; 




    @ObjectFactory 
    public IObjectFactory getObjectFactory() { 
     return new org.powermock.modules.testng.PowerMockObjectFactory(); 
    } 

    @Test 
    public void happyPath() 
    { 
     PowerMockito.mockStatic(CouchbaseCluster.class); 

    } 

} 



My pom includes following: 
<dependency> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.mockito</groupId> 
      <artifactId>mockito-all</artifactId> 
      <scope>test</scope> 
     </dependency> 
      <dependency> 
     <groupId>org.powermock</groupId> 
     <artifactId>powermock-module-testng</artifactId> 
     <scope>test</scope> 
     </dependency> 
     <dependency> 
     <groupId>org.powermock</groupId> 
     <artifactId>powermock-module-testng-agent</artifactId> 
     <scope>test</scope> 
     </dependency> 
     <dependency> 
     <groupId>org.powermock</groupId> 
     <artifactId>powermock-api-mockito</artifactId> 
     <scope>test</scope> 
     </dependency> 
     <dependency> 
     <groupId>org.powermock</groupId> 
     <artifactId>powermock-module-junit4</artifactId> 
     <scope>test</scope> 
    </dependency> 

     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <scope>test</scope> 
     </dependency> 

當我運行測試通TestNG的我收到此錯誤日誌PowerMockito不工作:-java.lang.NoClassDefFoundError:組織/的Mockito /內部/製作/ CglibMockMaker

java.lang.NoClassDefFoundError:組織/ mockito/internal/creation/CglibMockMaker at org.powermock.api.mockito.internal.mockmaker.PowerMockMaker。(PowerMockMaker.java:40) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect。 NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(D elegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at java.lang.Class.newInstance(Class.java:379) at org.mockito.internal.configuration。 plugins.PluginLoader.loadImpl(PluginLoader.java:61) 在org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:24)

回答

相關問題