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.
- 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.
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.
For archtype, select
If you are using other than JDK1.8, please select
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.
For the time being, let’s select the latest 2.0.0.
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.
groupID is demo and
artifactID is com.demo.
If the creation is successful as above, the directory structure will be as follows.
Run the test
When you open
AppTest.java, the test code is displayed as below, so click
The test will run.