tags:

views:

35

answers:

2

Is there an easy way to start a static function (not main) of a class in a few clicks in Eclipse?

Can do it in main function, but is there another way?

E.g. right click on a needed function in the Outline view and select [run with arguments..]

+1  A: 

Create a JUnit Test class for your static methods. Once created, it's only one click to test your static methods.

Thomas
+3  A: 

A static method cannot be run, except of course if this method is the main(String... args) method.

However, consider creating a JUnit test case for this method instead.

Create a JUnit Test Case within Eclipse. In the wizard, you can indicate the class that provides your static method in the Class under test: field. Then Eclipse will give you the ability to create one test method per existing method on the class under test.

Once your JUnit test is created, simply right-click on this Java class and select Run as > JUnit test. The shortcut is Alt+Shift+X, then T.

You can also consider doing some Test Driven Development...

romaintaz
@romaintaz Good answer, thank you.
EugeneP