How can I create Junit test cases in Eclipse?

Is there an easy way to create stubs for Junit4 tests in Eclipse (Galileo)?

+56
eclipse junit
Dec 12 '09 at 18:31
source share
2 answers

In the Package Explorer view, right-click the file for which you want to create a JUnit test. In the context menu that opens, select "Create" β†’ "Other ...". In the Select Wizard dialog box, select Java β†’ JUnit β†’ JUnit Test Case.

Then a dialog box opens. If you have a default Maven or Gradle project, you 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, a dialog box allows you to check which methods automatically create stubs for.

+84
Dec 12 '09 at 18:48
source share

You can also watch Fast Code Eclipse Plugin . After configuration, you can generate a junit / testng test by selecting a class or any method. Also gives you the opportunity to move from a method to all tests.

enter image description here

+6
Dec 15 '09 at 17:53
source share



All Articles