After getting ant to do my compiling, I decided to get it to run my unit tests. Which it can now do acceptably, though the path was a bit rockier than I would have liked. Some steps:
- Copy down an example from a book, mutatis mutandem.
- Hmm: ant says it doesn’t know about the junit task. Looks like it’s an optional task, so maybe it’s in a separate rpm? After not too much searching, yum install ant-junit does the trick. A bit annoying, except that I do approve of modular architectures and packaging that takes advantage of that.
- But ant is using GCJ while my code needs Sun’s Java 1.5. I dealt with this for the compile step; let’s see if I can deal with this for the test step? Yes, not hard to do. But it can’t find the code – is ant not passing my CLASSPATH setting to it? I guess so; how do I fix it? Not directly obvious from any of the documentation that I was looking at, but not too hard to figure out.
- But even if the tests fail, the task still passes. The book tells me what to do about that, and how to fix it. (And agrees that’s a design flaw.) Great; now everything seems to work.
- Except that half an hour or so later, I notice that only two-thirds of my tests are being run. I thought I verified earlier that they were all being run? There is a failing test currently – could the haltonfailure attribute really cause the test run to stop after the first failure, not after all of them? That sure sounds like a design flaw to me – if a change causes multiple tests to fail, that’s useful information. There seems to be no attribute to use that gives the behavior I want; sigh. The book, however, in its explanation of why you normally don’t want a test failure to halt the junit task (because you might want a subsequent task to format the results attractively, and then fail) shows a trick that I can use: I’ll set a property instead of halting the task when a test fails, and then the next task will fail if that property is set. Which works great.
So now everything is working fine. I’m still not overwhelmingly impressed by ant, though I imagine most tools would present similar stumbling blocks when you first learn to use them. I’m happy with the results; if I were planning to stick with Java for the long haul, I’d change things still further (in particular I’d run the acceptance tests and installation from within ant), but as is I’ll stick with what I’ve got.
Post Revisions:
There are no revisions for this post.