#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Create a test class (main method) to start(run) the class in Java


    Maybe I do not understand something.
    So I've created the class in Java, which does some stuff.I need to create a main method or mainClass, that will start(run) my class. (I do not mean JUnit).
    Question: how to do it?
    is there some sort of methodology?
    described in the books somewhere?

    Help me please
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    I usually just add a main() method to the class to be tested. In the main() method, create an instance of the class to be tested and depending on what that class's constructor does, you may need to call other methods in the class to start execution of the class.
    To start execution: java <ClassNameWithMainMethod>

    There must be lots of code examples here on this forum or on the net you can look at.
    Last edited by NormR; July 31st, 2012 at 01:59 PM. Reason: spelling
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0
    thank you
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Cross posted at http://www.javaprogrammingforums.com/java-theory-questions/17031-create-test-class-main-method-start-run-class-java.html

IMN logo majestic logo threadwatch logo seochat tools logo