Instructor: Todd Dole
Semester: Fall 2024
JUnit is a popular testing framework for Java. It allows coders to create unit tests, to test individual units of source code to ensure that each piece of a program is working as intended.
JGrasp supports JUnit 4. This is a slightly older version of the JUnit platform, but is more than adequate for us to learn the basics of writing unit tests in P1.
This guide will cover installing JUnit and configuring JGrasp to use it.
You will need to download two .jar files for JUnit. .jar stands for Java Archive. JAR files contain java classes and other resources, packaged into an easy to distribute format.
Here are direct links. Download these files, and place them into a new folder where you will be able to find them later. (For Windows, I recommend you create a JUnit-4 folder in Program Files (x86).
Once you have downloaded the files, in JGrasp, go to the Tools Menu and select JUnit-->Configure
Click the Browse button next to JUnit Home, and select the folder where you saved the .jar files earlier. Then click ok.
In order to use JUnit, we need to create a Project in JGrasp.
In JGrasp, Select the Project menu and click on New Project. Pick a name for your project--you can call it P1 or something similar. Click the box for Create New Directory, and then click next. Click next again, and then click Create.
Next, we need to tell our project where the .jar files are located.
Go to the Settings Menu, select PATH / CLASSPATH, and choose your project from the menu (Project P1, or whatever you called it in the earlier step.)
Select the CLASSPATHS tab, and click new.
Click the top Browse button, next to "Directory Path or JAR File". Navigate to where you saved the .jar files earlier, and select the first file, then click ok.
Repeat this process for the second .jar file. When you are done, you should have two entries under CLASSPATH.
Finally, click Apply and Ok to save.
If you were successful, you should now have several new buttons: