A memo that enabled VS Code + JUnit 5 to be used on Windows 10

It was necessary to prepare the environment for the subject, so I made a note of it until it started working. I'm not very familiar with this area, so there may be some deficiencies, but I hope it helps.

Download OpenJDK

There are several types of JDK, but here we will use OpenJDK. https://openjdk.java.net/ As of October 2020, the latest was JDK15, so download this for Windows. Download for Windows, unzip it, and place the "jdk-15" that appears in any folder.

Java Extension Pack installation

Install the Java Extension Pack from the VS Code extension. After installation, display the settings with Ctrl +,, search for "Java: Home", click "Edit with settings.json", and specify the folder of "jdk-15" placed above. At this time, it is necessary to overlap two backslashes as follows.

"java.home": "C:\\hoge\\hoge\\jdk-15"

Creating a Java project

When I select a folder and try to create a Java project, I get an error that the environment variable JAVA_HOME is not set.

Error: JAVA_HOME not found in your environment. 
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Start PowerShell with administrator privileges and set the Java storage path in the system environment variable JAVA_HOME with the following command. [System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\hoge\hoge\jdk-15", "Machine") Then restart VS Code. (The above error was not resolved without rebooting.)

Generate a Java project again and set various IDs.

Define value for property 'groupId': (Specify what you want to be the package name)
Define value for property 'artifactId': (Specify what you want to be the jar name)
Define value for property 'version' 1.0-SNAPSHOT: : (Leave the default value without entering)
Define value for property 'package' (What you entered in groupId): : (Leave the default value without entering)

Open the generated Java project folder with VS Code, and the project creation is complete.

Run build

In the Explorer pane of VS Code, right-click App.java under the src folder and execute "Run" to build it, and "Hello World!" Is output to the terminal.

Change from JUnit 4 to 5

If you created a Java project as it is, JUnit4 was used, so change it to JUnit5. Since there is a sample project of JUnit5, change the pom.xml of the created project by referring to the pom.xml. https://raw.githubusercontent.com/junit-team/junit5-samples/r5.7.0/junit5-jupiter-starter-maven/pom.xml

This time I changed it like this.

+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.junit</groupId>
+        <artifactId>junit-bom</artifactId>
+        <version>5.7.0</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
   <dependencies>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>

When you save pom.xml, a dialog asking if you want to synchronize is displayed. Click "Now" to synchronize. You can now use JUnit 5.

Recommended Posts

A memo that enabled VS Code + JUnit 5 to be used on Windows 10
Connect with VS Code from a Windows client to Docker on another server
Java 14 new features that could be used to write code
A memo to start Java programming with VS Code (2020-04 version)
Building a haskell environment with Docker + VS Code on Windows 10 Home
Until ruby can be used on windows ...
A memorandum when IME cannot be turned on with VS Code (Ubuntu 20.04)
[Android] I want to create a ViewPager that can be used for tutorials
How to configure ubuntu to be used on GCP
How to display a browser preview in VS Code
A concise summary of Java 8 date / time APIs that are likely to be used frequently
A collection of commands that were frequently used on heroku
Create a page control that can be used with RecyclerView
The case that @Autowired could not be used in JUnit5
Firebase-Realtime Database on Android that can be used with copy
Find a Switch statement that can be converted to a Switch expression
A memo to build Jitsi Meet on Azure with docker-compose
Try debugging natural language processing on Windows. with VS Code
Convert an array that may be null to a stream
A collection of patterns that you want to be aware of so as not to complicate the code
[Swift5] How to create a .gitignore file and the code that should be written by default
Run VS Code on Docker
Introduction to JUnit (study memo)
Create a VS Code Plugin.
Static analysis tool that can be used on GitHub [Java version]
I want to use swipeback on a screen that uses XLPagerTabStrip
[Ruby 3.0] A memo that I added a type definition to a library I wrote
I made a question that can be used for a technical interview
How to open a script file from Ubuntu with VS code
Let's write a code that is easy to maintain (Part 2) Name
Build a Docker-based development environment on Windows 10 Home 2020 ver. Part 2 VS Code should make the Docker development environment comfortable
How to override in a model unit test so that Faker can be used to generate random values