Environment construction procedure for using PowerMock with JUnit

table of contents

  1. Environment construction procedure for using PowerMock with JUnit ← Now here
  2. Mock and Spy in PowerMock
  3. Mock static methods with PowerMock
  4. Mock the constructor with PowerMock
  5. Mock private methods with PowerMock
  6. Try using PowerMock's WhiteBox
  7. Disable static initializer in PowerMock

Overview

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.

environment

version
eclipse Eclipse IDE 2020‑03
java 1.11
junit 4.12
mockito 2.23
powermock 2.0.2

download

Download the complete library from PowerMock official website.

Select Downloads at the bottom of the page. download_01.png

Select powermock-mockito2-junit-2.0.2.zip. download_02.png

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. download_03.png

Select byte-buddy-1.10.14.jar. download_04.png

Creating an eclipse project

Create a sample_powermock project under workspace and copy the set of libraries downloaded earlier to the lib folder. projectsetup_01.png

Add to build path. projectsetup_02.png

Now you're ready to go.

Link Collection

Recommended Posts

Environment construction procedure for using PowerMock with JUnit
[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
Environment construction with Docker for beginners
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
Wordpress local environment construction & development procedure with Docker
Stable development environment construction manual for "Rails6" with "Docker-compose"
Gradle settings for using JUnit 5
[Docker] Rails 5.2 environment construction with docker
React environment construction with Docker
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
Rails + MySQL environment construction with Docker
Node.js environment construction with Docker Compose
Environment construction for Servlet application development
[Unity] Android development environment construction procedure
Rails on Docker environment construction procedure
[Environment construction with Docker] Rails 6 & MySQL 8
CentOS8 + Anaconda 4.9.2 + jupyterhub environment construction procedure
[Java & SpringBoot] Environment Construction for Mac
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
CentOS8 + Anaconda + Django development environment construction procedure
Notes for using BLE with iOS apps
Rails environment construction with Docker (personal apocalypse)
Laravel development environment construction with Docker (Mac)
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Rails API server environment construction using docker-compose
Laravel + MySQL + phpMyadmin environment construction with Docker
Modern Java environment for Windows using Chocolatey
Using Material Design for Bootstrap with Rails 5.2
Environment construction summary with rvm and postgresql
Spring Boot environment construction with Docker (January 2021 version)
Introduction to Robot Battle with Robocode (Environment Construction)
[Java] How to test for null with JUnit
[Jakarta EE 8 application development with Gradle] 1. Environment construction
[For beginners] I tried using JUnit 5 in Eclipse
Environment construction command memo with Docker on AWS
Kaggle environment construction using official Docker and vscode
CI / CD practice for beginners --Part1 --Environment construction
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Procedure for operating google spreadsheet with API (ruby)
JAVA + STS (Spring Tool Suite) environment construction procedure
Procedure for publishing an application using AWS (5) Publish an application
Development environment construction using IntelliJ IDEA + Maven + Tomcat 9
[Note] Struts2 environment construction using Gradle in Eclipse
DB environment construction with DBFlute Intro + H2 Database
[Rails] Procedure for linking databases with Ruby On Rails
Test code using mock with JUnit (EasyMock center)
React + Django + Nginx + MySQL environment construction with Docker
[For beginners] Procedure for creating a controller using rails
Introduction to kotlin for iOS developers ①-Environment construction
Tips for testing with mock for classes using @value
Django development environment construction using Docker-compose (personal memorandum)
WebSphere Liberty for Windows development environment maintenance procedure
[Java] Environment construction
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
Java environment construction
[Spring] Environment construction
Docker environment construction
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
Environment construction of Rails5 + MySQL8.0 + top-level volumes with docker-compose
Procedure for publishing an application using AWS (6) Introduce Nginx