aspose file tools*
The moose likes Testing and the fly likes Inner static class as test harness Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Inner static class as test harness" Watch "Inner static class as test harness" New topic
Author

Inner static class as test harness

Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Junit in action, nice name but Jess in action sound more savvy :roll: just an opinion.
Anyway, I have yet to embark on any "testing suite". I've heard of Junit but not sure what it is.
I use an idea that I picked up from Allen Holub in his book Taming Java Threads. The idea is simple; create a static inner class for every class that you wanna test. For testing, you just invoke the Test as in:

Finally, for deployment, you simply remove all Test classes.
My questions to the author:
  • What's the advantage of Junit over the aforementioned?
  • Is it possible to incorporate this method with Junit?
  • What's a "testing framework" anyway?


  • Finally, is it worth the effort to learn Junit or getting the book?
    Thanks,
    Leslie


    Normal is in the eye of the beholder
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    What's the advantage of Junit over the aforementioned?
    JUnit lets you run thousands of tests with a single mouse-click (or Ant target, or whatever). In general, JUnit has all sorts of test structuring features built-in.
    Finally, is it worth the effort to learn Junit or getting the book?
    Definitely. Testing is a must for improving quality and JUnit is the defacto standard testing framework for Java.


    Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
    Leslie Chaim
    Ranch Hand

    Joined: May 22, 2002
    Posts: 336
    Originally posted by Lasse Koskela:
    Definitely. Testing is a must for improving quality and JUnit is the defacto standard testing framework for Java.

    Ok, I'm convinced. Where do I start?
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    Originally posted by Leslie Chaim:
    Ok, I'm convinced. Where do I start?
    Test Infected would be a good start. There are also other docs at junit.org.
    john guthrie
    Ranch Hand

    Joined: Aug 05, 2002
    Posts: 124
    benefits of junit:
    1) to reiterate, junit has a framework that uses reflection to automatically gather up and run many unit tests
    2) junit has solid ant support, making automatin even easier
    3) junit's ant support give you the ability to create a swanky-looking html report that shows all the results of the unit test runs. we use this on our continuous build machine
    Leslie Chaim
    Ranch Hand

    Joined: May 22, 2002
    Posts: 336
    Is it open source?
    Stefan Bell
    Ranch Hand

    Joined: Aug 26, 2003
    Posts: 82
    Yes it is open source and my favorite feature is the testsuite where you can set up all your tests and like was previously stated, one click runs them all.
    Ernest Friedman-Hill
    author and iconoclast
    Marshal

    Joined: Jul 08, 2003
    Posts: 24183
        
      34

    I would just like to point out that the static inner test class idea and JUnit are not mutually exclusive, and in fact, we sometimes use static inner test classes and JUnit together. If you write your JUnit TestCases as inner classes, then they have access to the private data in a class, making it easier to test.
    As a general rule, it's better to test using only the public interface of a class, if you can; but in cases where that would uglify things significantly, the static inner TestCase is your best friend.


    [Jess in Action][AskingGoodQuestions]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Inner static class as test harness