Feeds:
Posts
Comments

Archive for May, 2010

Test Version: GWT 2.0 and above

Use of “main” method

Each Java class can include a “main” method to perform class execution. This feature is especially useful for experimenting, testing and debugging the pertaining code within the class without resorting to using helper class. Generally it is more efficient and productive to test a particular class (if one already pinpoint the problematic class) rather than to test a whole application that has more overheads and which takes longer time to run. By including a “main” method in class, other developers can also quickly experiment with different API of the code within the class without creating additional testing helper classes. In addition, it is easier to build a reliable application if the classes that make up the application are reliable themselves. Apart from this, the use of “main” method will also encourage one to design the class to be “simplified” so that it can easily test from “main” method.

public static void main(String[] args) // Java’s main method

That to say that the “main” method is not a replacement for unit testing, and vice versa. Their intent and usage are different. Unit testing is more formal whereas the “main” method is less formal. Many test cases are included in unit testing and is run periodically to ensure that nothing break the code and create bug from modified code as in the case of time-consuming build process. Unit testing is usually automated and does not involve GUI interaction since the unit testing can be invoked in command-line prior to software development process like build process or check perform by version control system after code check-in.

On the other hand, the “main” method does not subject to such intense test and is not run unless one modify that class and want to have a quick test ensure correct behaviour and result. Developers are free to change whatever in the “main” method of the class during development as long as the “main” method of the class is not used to start up the application, and not call by other classes (It is bad practice to reference and use “main” method from other class.).

 

(more…)

Read Full Post »