[Java] I tried using Junit with Mac VScode Maven

1 minute read


For the time being, it is for those who want to experience unit testing using JUnit with VS Code. I haven’t even put Java on my Mac yet! If you are interested, please refer to here.

Operating environment

  • macOS: Catalina 10.15.5
  • VSCode: 1.46.1
  • Java: Amazon Correto 1.8.0_252

You can use any other JDK, but for now I’ll use 1.8.

Install Java extension in VScode

First, let’s put Java Extension Pack in VS Code. Screenshot 2020-06-20 1.47.40.png

This also includes Maven extensions and is now required.

Create Maven project

After installing the extension, open the command palette with Cmd + Shift + p and select Maven: Create Maven Project.

Screenshots 2020-06-20 1.52.33.png

For archtype, select archtype-quickstart-jdk8. If you are using other than JDK1.8, please select maven-archtype-quickstart. In that case, please note that the execution result after this may change. For the time being, I’m only thinking of running JUnit easily.

Screenshot 2020-06-20 2.45.45.png

For the time being, let’s select the latest 2.0.0.

Screenshots 2020-06-20 2.00.32.png

You will be asked where to create it, so select any directory. Then you will be asked what kind of project you want to create interactively in the VS Code terminal. This time I created it as follows.

 Screenshot 2020-06-20 2.07.47.png

groupID is demo and artifactID is com.demo. If the creation is successful as above, the directory structure will be as follows.

Screenshots 2020-06-20 2.20.39.png

Run the test

When you open AppTest.java, the test code is displayed as below, so click Run Test. The test will run.

Screenshot 2020-06-20 2.35.53.png