Trybotics Logo

Creating a JUnit Test Case in Eclipse

DESCRIPTION

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.

Description:

Click on the Eclipse Java Neon Icon on the Desktop, or search for Eclipse in the search Box.

Description:

On the top navigation bar, Click Project. In the drop-down menu, click Properties.

Description:

First, Click on ‘Java Build Path’ on the left-hand side. Then, click on ‘Libraries’ on the right side near the top.

Description:

Click on the ‘Add Library…’ Icon on the right-hand side.

Description:

First, Click ‘JUnit’ to make sure it’s highlighted. Then, Click the ‘Next >’ Icon on the bottom.

Description:

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'.

Description:

Click on 'Apply and Close' near the bottom right of the window.

Description:

Being on the main screen in Eclipse, Click on File, New, JUnit Test Case using the drop-down menu.

Description:

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.


YOU MIGHT ALSO LIKE