Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner static class as test harness

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • 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
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • 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
    • 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
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • 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.
     
    john guthrie
    Ranch Hand
    Posts: 124
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Is it open source?
     
    Stefan Bell
    Ranch Hand
    Posts: 82
    • Mark post as helpful
    • send pies
    • 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.
     
    Ernest Friedman-Hill
    author and iconoclast
    Marshal
    Pie
    Posts: 24208
    35
    Chrome Eclipse IDE Mac OS X
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic