Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Beginner
Sep 23, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Include Test Code in Your Classes

It is important for developers to test code that they write to insure that they are meeting the specifications for their application. Often test code is built in a separate program which loads and tests a particular class. Instead, you can include test code directly inside your class and place it in a "main" method.

When you run a Java program from the command line:

 java ApplicationStartingClass
you supply the name of the class that contains the start up code. Java execute a specific method in that class, the "main" method:
 public class ApplicationStartingClass
   public static void main( String[] args )
      . . .
You can use this feature of Java to embed test code inside each of the classes that you write. If you are working developing the class Person, you can include a main method in the class, even though it will never be called during normal use.
 public class Person
   . . .
   public static void main( String[] args )
      // include test code which exercises the class Person
When you need to test your class, you simply run the class from the command line:
 java Person
Randy Kahle
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date