Aren't out-of-container tests supposed to be faster?
Earlier this week, I converted my StrutsTestCase tests from using CactusStrutsTestCase to MockStrutsTestCase. At first, this seemed like a great thing - on my Windows XP box. To run all the tests in AppFuse, it takes around 2:20. I know, this is quite a bit of time for unit tests - but it was 3:15 in version 1.5. At least it's faster than it was. 1:20 of this is for starting Tomcat and running Canoo WebTests.
This all seemed great until I ran "ant test-all" on my PowerBook tonight. It averages around 7:00 minutes. WFT?! I know PowerBooks are slow - but they're not that slow. I'm guessing the reason is because Spring's ApplicationContext is loaded by each test - whereas the Cactus versions would always grab it out of the ServletContext. Sounds like I need a TestSuite.
What if I isolate and compare times for just the "test-web" target? This target runs all the Action, Filter and Listener tests. Time to execute on Windows: 33 seconds, PowerBook: 2 minutes 21 seconds. What about just testing the JSPs (with Cargo)? Windows: 1:24, PowerBook: 3:32. My Windows desktop has 1.5 GB RAM and a 2.6 GHz processor. My PowerBook has 1 GB RAM and 1.5 GHz. I agree that it seems like an unfair comparison - but AppFuse tests ran in around 4 minutes on the PowerBook in the last release. I guess it's back to the drawing board.
Update: Nevermind. I just downloaded and checked out AppFuse 1.5 - almost 8 minutes for running all the tests. If I were going to work on my PowerBook for my next project, I'd refactor AppFuse Managers and Actions to use jMock. Luckily I'm using my Windows machine.
Update 2: I found a solution! Using Ant 1.6.2's forkmode="once", I was able to reduce the time of the test-web target from 2:21 to 24 seconds on my PowerBook!! Windows: :33 -> :18. Running "ant test-all" on the Mac is now 2:15 - while the Windows version is 2:20.
WTF!? My PowerBook is actually faster than my Windows box? I never thought I'd see the day - Yeeee haaawwww!!
Now I just have to figure out how to detect 1.6.2 and warn users if they aren't using it.
Posted by Robert Watkins on October 06, 2004 at 06:42 AM MDT #
Posted by Perryn Fowler on October 06, 2004 at 08:31 AM MDT #
Posted by Brian McCallister on October 06, 2004 at 11:15 AM MDT #
Posted by Stefan Bodewig on October 07, 2004 at 06:40 AM MDT #
Posted by Bruce Snyder on October 07, 2004 at 12:00 PM MDT #
Posted by Kurt Wiersma on October 07, 2004 at 01:53 PM MDT #
In reality, I've found that the way I'm doing things in AppFuse makes it easier to write tests than using EasyMock or JMock. Since most tests only take a second or two to run, and they test full integration - the current tests certainly aren't a <em>bad thing</em>. Isn't the most important thing to get our jobs done fast and efficiently instead of playing with all the latest mock stuff anyway. ;-) I do think my perspective is scewed because I tend to write full apps rather than just a layer. If I were working on a team where I was responsible for one tier, I'd probably use mocks a lot more so I wasn't dependent on other's code.
As for the DAO layer of AppFuse, I'll probably always keep that as integration tests that talk to a real database. I've found quite a few issues b/w the different databases that I wouldn't have found if I'd mocked the database. BTW, aren't you supposed to only mock your own APIs?
My plan for AppFuse 1.7: no mocks in DAO tests, mock DAOs in Manager tests, mock Managers in Action/Controller tests and use JSP tests (i.e. Canoo WebTest or jWebUnit) tests to verify full integration.
Posted by Matt Raible on October 07, 2004 at 02:44 PM MDT #
Posted by 59.144.12.41 on June 09, 2006 at 11:57 AM MDT #