How can I create stub Junit tests in Eclipse?

EclipseJunit

Eclipse Problem Overview


Is there a simple way of creating stubs for Junit4 tests in Eclipse (Galileo)?

Eclipse Solutions


Solution 1 - Eclipse

In the Package Explorer view, right-click on the file that you would like to create a JUnit test for. In the opened context menu, select New -> Other... . In the Select a wizard dialog, select Java -> JUnit -> JUnit Test Case .

Then a dialog opens. In case you have a default Maven or Gradle project, you will probably have to change the default Source folder from the provided ${PROJECT_NAME}/src/main/java to ${PROJECT_NAME}/src/test/java. If you click Next, the dialog allows you to check which methods to automatically create stubs for.

Solution 2 - Eclipse

You might also look into Fast Code Eclipse Plugin. Once you configure you can generate junit/testng test by selecting the class or any method. Also gives you way to navigate from a method to all the tests.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpeter.murray.rustView Question on Stackoverflow
Solution 1 - EclipseMichael PattersonView Answer on Stackoverflow
Solution 2 - EclipsefastcodejavaView Answer on Stackoverflow