This discussion is archived
4 Replies Latest reply: Mar 26, 2008 8:39 PM by 807591 RSS

programatically run JUnit tests

807591 Newbie
Currently Being Moderated
I have a *.class file that a contains the class that I want to test and a *.class file contains the JUnit test. I need to programatically run the tests. Anyone have aby ideas where to start?
  • 1. Re: programatically run JUnit tests
    807591 Newbie
    Currently Being Moderated
    http://www.google.com/search?hl=en&q=JUnit+%2B+executing+from+the+command+line

    Should give you what you want to know. Happy reading.

    PS.
  • 2. Re: programatically run JUnit tests
    807591 Newbie
    Currently Being Moderated
    Not no sure how this would help. I would like to write a java program that runs the JUnit test. Surly any command line based solution would remove platform independence?
  • 3. Re: programatically run JUnit tests
    DrClap Expert
    Currently Being Moderated
    It seemed to me that this should be easy to do, based on what I've heard about JUnit. So I went a-googling and I found [an article|http://clarkware.com/articles/JUnitPrimer.html] that explained how to run JUnit tests. It said:

    "To run our test case using the textual user interface, use:

    java junit.textui.TestRunner ShoppingCartTest"

    So there you go. Put this into your Java program:
    junit.textui.TestRunner.main(new String[] {ShoppingCartTest});
  • 4. Re: programatically run JUnit tests
    807591 Newbie
    Currently Being Moderated
    Have you tried the Eclipse IDE? I use it to run JUnit tests on Mac OS X and Windows XP - just press a button - no command line.. er.. commands. Probably works for other platforms too. Other IDEs might have the same functionality.

    Or you could code a TestSuite...

    Jeff Langr's book, Agile Java covers JUnit testing quite comprehensively.