Java – set powemockito static

I want to use powermock and mockito to simulate some static method calls I have followed the instructions and examples of so and the powermock getting started and mockstatic pages, but I have not completed a mockstatic () call

When I called mockStatic (foo.class) from the test class, I was given the exemption:

java.lang.NoClassDefFoundError: org/Mockito/mock/MockName
at org.powermock.api.mockito.powermockito.mockStatic(powermockito.java:70)
at ...my test class method call...

I'm sure it's a setup problem because I've found that the term used for setup is quite confusing I got mockito zip from powermock downloads In eclipse (3.5.2), I opened the project properties and added all jars to the build path I also tried to add the entire extracted powermockito folder to my environment vars classpath, and then just the one dedicated to powermockito jar didn't solve it

I also have these comments in the class level of the test class. According to the powermock instruction:

@RunWith(PowerMockRunner.class)
@PrepareForTest(ApplicationContextLoader.class)

There are also these powermock specific imports:

import org.powermock.api.mockito.powermockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

For those who have used powermockito before, even if it is just a pointer in the right direction, it will be very helpful to check things I'm trying to see that my settings use the same syntax as I see - where can I see it

Solution

It is possible that the versions of powermock and mockito are incompatible To solve this problem, it will not be a problem

Mockito                     PowerMock
1.10.8+                     1.6.2+
1.9.5-rc1 - 1.9.5           1.5.0 - 1.5.6
1.9.0-rc1 & 1.9.0           1.4.10 - 1.4.12
1.8.5                       1.3.9 to 1.4.9
1.8.4                       1.3.7 & 1.3.8 
1.8.3                       1.3.6
1.8.1 & 1.8.2               1.3.5
1.8                         1.3
1.7                         1.2.5

See: https://github.com/jayway/powermock/wiki/MockitoUsage

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>