Installation of JUnit 5
We shall discuss how to install JUnit5. JUnit5 will be studied later on. Unlike JUnit4 we cannot just download 2 jar files and make things work. We need to work with Maven and "pom.xml" . First install Maven. Maven is a build tool. The reason we need Maven is that it will automatically download all the needed jars. You can do so from the web site :
http://maven.apache.org/download.cgi
I downloaded the zip file and extracted it to my root folder to get the folder:
C:\apache-maven-3.6.3
Create a folder in "C:\JUnit" called "test2" .
Open a dos command session and type:
set path=c:\jdk18\bin;C:\apache-maven-3.6.3\bin;%path%
Now execute the below command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
This will create a folder called "my-app" in our "test2" folder. The structure of this folder will look like:
C:\JUnit
test2/my-app
src
main
\java\com\mycompany\app
Calculator.java
test
\java\com\mycompany\app
CalculatorTest.java
pom.xml
Place the file "Calculator.java" in the source main folder.
Place the file "CalculatorTest.java" in the test folder. The file "pom.xml" should have entries of the form:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Now from the "my-app" folder run the command:
C:\junit\test2\my-app>mvn test