• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner static class as test harness

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Leslie Chaim
    Ranch Hand
    Posts: 336
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Ranch Hand
    Posts: 124
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 336
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Is it open source?
     
    Ranch Hand
    Posts: 82
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    author and iconoclast
    Posts: 24207
    46
    Mac OS X Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    After some pecan pie, you might want to cleanse your palatte with this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic