Creating a JUnit Test Case in Eclipse
by YusufT13 in Circuits > Software
9537 Views, 0 Favorites, 0 Comments
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.
Open Eclipse
Click on the Eclipse Java Neon Icon on the Desktop, or search for Eclipse in the search Box.
Properties
On the top navigation bar, Click Project. In the drop-down menu, click Properties.
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.
Add Library
Click on the ‘Add Library…’ Icon on the right-hand side.
JUnit
First, Click ‘JUnit’ to make sure it’s highlighted. Then, Click the ‘Next >’ Icon on the bottom.
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'.
Apply the Changes
Click on 'Apply and Close' near the bottom right of the window.
New JUnit Test File
Being on the main screen in Eclipse, Click on File, New, JUnit Test Case using the drop-down menu.
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.