Introduction: Creating a JUnit Test Case in Eclipse
To test Java code in Eclipse, the programmer must write his/her own tests. JUnit Tests are most often used by experienced programmers to verify the correctness and efficiency of their code. This style of testing is taught in most Universities, such as DePaul University, and is encouraged to be used by students to test their homework solutions. The level of difficulty of creating the test cases is minimal, however creating the JUnit Test file is difficult for any beginner. An example JUnit Test file is pictured.
Step 1: Open Eclipse
Click on the Eclipse Java Neon Icon on the Desktop, or search for Eclipse in the search Box.
Step 2: Properties
On the top navigation bar, Click Project. In the drop-down menu, click Properties.
Step 3: Java Build Path
First, Click on ‘Java Build Path’ on the left-hand side. Then, click on ‘Libraries’ on the right side near the top.
Step 4: Add Library
Click on the ‘Add Library…’ Icon on the right-hand side.
Step 5: JUnit
First, Click ‘JUnit’ to make sure it’s highlighted. Then, Click the ‘Next >’ Icon on the bottom.
Step 6: JUnit Version
Click on the dropdown menu next to ‘JUnit library version:’. Select the Latest Version available, i.e. JUnit 4 or JUnit 5. Then click 'Finish'.
Step 7: Apply the Changes
Click on 'Apply and Close' near the bottom right of the window.
Step 8: New JUnit Test File
Being on the main screen in Eclipse, Click on File, New, JUnit Test Case using the drop-down menu.
Step 9: Finish Creating the File
Next to the ‘Name:’ Box, write in the name of the test file. A default file name is written by Eclipse, but this can be changed. Then, Click ‘Finish’ at the bottom.
1 Person Made This Project!
- hadisaeedeh made it!