Saturday, February 5, 2011

Forcing mandatory unit tests when pushing to the central repository

For the past few days I've been working on getting our build process automated to deploy to a local server (since we have no remote host as of yet). It's deceptively simple:
  1. build java source files (including tests)
  2. copy compiled class files to deploy directory
Sounds easy, right? It should be, but my relative inexperience with web apps translates into spending extra time configuring environment variables, searching out libraries and putting them in the right place, etc. But hey, that's finished now!


The real issue I wanted to tell you about is related: We want to make sure our unit tests are run each time someone tries to push to the production branch of our central repository, to make sure they haven't broken. I figure we also want to test them outside are local environment, let's say the directory of the local server we test on.
So we add a preoutgoing hook to mercurial that simply launches an ant script that will run the unit tests and the push will fail if the tests fail. To get this working though, my process resembled this less-than-ideal workflow:
  1. build java source files (including tests)
  2. copy compiled class files to deploy directory
  3. call junit task from within Ant
  4. Observe that _x_ is not in the right place
  5. Put _x_ in the right place
  6. Repeat
Where _x_ usually refers to hibernate and one of its xml files. Figures. However, after hours of pain and realizing that I had pointed the ant script to the wrong version of Tomcat, this process now resembles the ideal process at the beginning. I'm pretty happy with it, I just hope it continues to work...

No comments:

Post a Comment