Taming the MXUnit Ecplise Plugin with Apache Alias

2008 March 09
tags: Apache · MXUnit · Unit Testing
by Paul Marcotte
If you are into Unit Testing and haven't yet heard of MXUnit, I definitely recommend giving it a whirl. Some things that stand out for me, thus far in my evaluation, are the simple, but extensible, assertions, the ecplise plugin, and the debug output. One gotcha that has come up for people when using the eclipse plugin, is that is was designed assuming that the package path to your components resolves directly from your web root. For people who run separate server instances, virtual machines, or develop locally with Apache virtual hosts, this is a show stopper. Luckily, for folks, like myself, who prefer to develop locally with Apache, getting the MXUnit eclipse plugin to work is simply a matter of adding a couple of Alias directives to your vhost.I've taken to using top level domain names to differentiate between local, staging and production web sites. This makes is easy to keep the same sub-domain names if the project calls for it. When developing for a client, I will often provide a demo site at fancybread using the project name as a sub-domain. For this type of development, I would then have two urls, myproject.fancybread.local and myproject.fancybread.com My virtual host for local dev would run like this. <VirtualHost 127.0.0.1:80>
DocumentRoot "/Users/paul/htdocs/myproject/root"
Alias /mxunit "/Users/paul/htdocs/mxunit"
Alias /myproject/root "/Users/paul/htdocs/myproject/root"
ServerName project.fancybread.local
DirectoryIndex index.cfm
<Directory "/Users/paul/htdocs/myproject/root">
Options All
AllowOverride All
</Directory>
</VirtualHost>
On my Mac, /Users/paul/htdocs is my localhost web root, and the document root for myproject.fancybread.local is /Users/paul/htdocs/myproject/root. In eclipse, I would then have a project called "myproject". To use the MXUnit eclipse plugin with a local development setup like mine, you need to use Apache Alias directives to get the plugin to recognize the path to your test cases. In the virtual host above, the first alias above is to the MXUnit framework files, the second is my eclipse project name and the folder therein where my project web root is located. And within eclipse I set the project properties to direct the test runner url to use my virtual host instead of localhost. Now that I've gone through the effort to get the eclpise plugin working and since I'm pretty fresh to Unit Testing altogether, it looks like I'll be working with MXUnit from here on out.