How to install JUnit 4 on MacOS Catalina

Posted By Aung Nay on Nov 22, 2020

Step 1: Verify Java Installation

Open Terminal check Java version.

java -version

You should get an output similar to this.

java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)

If you do not have Java on your mac, install JDK from

Azul JDK

Open JDK 15

Oracle JDK

Install using instructions from respective sites.

Step 2: Set JAVA_HOME

Using Finder Go to Folder, go to /Library/Java/JavaVirtualMachines/ and verify that /jdk-XX.XX.XX.jdk/Contents/Home/bin/ folder exist and that there are Unix executables including java and javac. (XX means numbers based on your Java installation.)

In Terminal,

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-XX.XX.XX.jdk/Contents/Home

(Make sure you replace XX with the actual numbers from what you see in Finder.)

Verify Java install by using java -version command again.

Restart Terminal and test by entering


Your output should show the path you just set.

Step 3: Download JUnit 4

Go to and download junit.jar and hamcrest-core.jar. The file names should be junit-X.XX.X.jar and hamcrest-core-X.X.jar. (XX means numbers.)

Create a folder name JUNIT in your Home using Finder. Move both files from Downloads to JUNIT folder.

Step 4: Setting JUNIT_HOME and CLASSPATH

Catalina uses zsh, so edit your .zshrc file (It’s a hidden file). Go to your Home folder using Finder. Hold down Cmd + Shift + “.” (That’s the dot). Finder will now show you all the hidden files.

If .zshrc file does not exist, using Terminal to create .zshrc file by typing in touch ~/.zshrc

Open .zshrc file with a text editor, paste the following commands and save it.

export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-X.XX.X.jar:$JUNIT_HOME/hamcrest-core-X.X.jar"

(Don’t forget to replace the XXs with numbers.)

Now, restart your Terminal and test the following:


The output should show the path you just set.


The output should show the path you just set for both files.

Step 5: Test JUnit Setup

Follow Step 6 and 7 from


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This