Open the JUnit Demo and download the files into a folder named junitDemo
.
The test will pass because there is nothing in it. You should complete the TODO sections.
-
Open the folder
junitDemo
-
You will notice that there is a lib folder with jar files, those are important for
JUnit
-
Under the
junitDemo
folder, run these commands:-
Mac Users:
- Compile:
javac -cp libs/junit-4.13.2.jar:libs/hamcrest-core-1.3.jar:. DemoArrayImplTester.java
- Execute:
java -cp libs/junit-4.13.2.jar:libs/hamcrest-core-1.3.jar:. org.junit.runner.JUnitCore DemoArrayImplTester
- Compile:
-
Windows Users:
- Compile:
javac -cp ".;libs\junit-4.12.jar;libs\hamcrest-core-1.3.jar" DemoArrayImplTester.java
- Execute:
java -cp ".;libs\junit-4.12.jar;libs\hamcrest-core-1.3.jar" org.junit.runner.JUnitCore DemoArrayImplTester
- Compile:
-
Command explanation:
javac
: compiles the folderlibs/junit-4.13.2.jar:libs/hamcrest-core-1.3.jar:.
JUnit4 dependenciesDemoArrayImplTester.java:
the tester file we want to compile and run
-
-
Open the folder
junitDemo
in VSCode. You might notice that there are some red errors. -
Open the tester file
DemoArrayImplTester.java
. -
On the left side of VSCode, there are ICONS, please click on the icon that looks like a beaker. If there is no beaker, please go to "Manage" - "Extensions", and install "Extension Pack for Java". This beaker will show up if you have the tester file
DemoArrayImplTester.java
open. -
Please Enable Java Test and select JUnit (NOT JUnit Jupiter).
-
Then you will see the unit Tests if they pass or fail. All of them will pass but this image below is an idea of what should look like.