By introducing PowerMock, you will be able to mock static methods / private methods / constructors that Mockito alone could not. This article is intended for beginners of PowerMock, but if you understand how to use Mockito as a prerequisite knowledge, you will be able to proceed smoothly. You can also get the sample code used in the article from GitHub.
version | |
---|---|
eclipse | Eclipse IDE 2020‑03 |
java | 1.11 |
junit | 4.12 |
mockito | 2.23 |
powermock | 2.0.2 |
Download the complete library from PowerMock official website.
Select Downloads at the bottom of the page.
Select powermock-mockito2-junit-2.0.2.zip.
powermock-mockito2-junit-2.0.2.zip should contain the libraries that powermock depends on, but this is not enough, from ByteBuddy Official Site You need to download byte-buddy.jar. (As of 09/11/2020)
Select Download.
Select byte-buddy-1.10.14.jar.
Create a sample_powermock project under workspace and copy the set of libraries downloaded earlier to the lib folder.
Add to build path.
Now you're ready to go.
Recommended Posts