Mock Shmocks!
Let me start this post by saying that I've never used Mock Objects in my JUnit tests. Simon digs it, crazybob is an advocate and so is the gang that wrote Open Source Programming. In fact, the OSP book says that your unit tests should only take a couple of seconds to run! A couple of seconds!? Mine aren't that fast, which definitely makes me think I should look at Mocks to try to speed things up.
However, there is a method to my madness. Almost all my tests depend on a database connection and use DBUnit to populate the database before running. This can be time consuming, but it's not too bad for what I'm getting: real tests that verify the environment, not just the code. I just ran all tests in the application - 8 minutes 7 seconds - for 165 JUnit/Cactus tests and ~25 WebTest (JSP) tests.
If I did use Mocks, I wouldn't have discovered all the bugs in my code this week. When migrating from MySQL to DB2, I found that some things worked on MySQL, but they didn't on DB2. I modified the code, doing some tweaks to make Hibernate happy, and voila - now everything works on DB2 and MySQL. Furthermore, all my errors occurred when running my app in the container, and when I used simple JUnit tests (on my Managers) to test the same logic, it worked.
Who knows, I'm definitely learning new stuff everyday. Maybe it's possible that Mocks could do all this, but testing the production environment seems pretty important to me.
Posted by Pascal Thivent on January 22, 2004 at 03:06 AM MST #
Posted by Ara Abrahamian on January 22, 2004 at 12:28 PM MST #
Posted by Erik Hatcher on January 22, 2004 at 12:54 PM MST #
Posted by Chris Kreussling on January 27, 2004 at 07:30 PM MST #
-Mockrunner for testing custom tags
-Strutstestcase for testing actions
As for the business logic and data access. I really like hibernate. If you have the choice, hibernate works with POJOs which are a dream to unit test your BL with. Hibernate on Hypersonic is fast enough for me.
Also, please remember the difference between MockObjects and Stubs. Stubs just replace a level/section of your architecture with a faked out version that returns dummy/known data that the caller can test with. A MockObject tests the caller of that layer/section from the INSIDE. Please read: http://www.connextra.com/aboutUs/mockobjects.pdf
Posted by Paul Kilroy on January 31, 2004 at 03:58 AM MST #