Eclipse JUnit Music Box

I wrote an Eclipse plugin that turns Eclipse's built-in JUnit runner into a music box. The following video demonstrates the plugin:

Each test class is assigned one of seven chords in the key of C major. The assignment is deterministic, so a particular sequence of tests will play the same "song". Passing test methods play a pleasing arpeggio, while failing tests play an ugly dissonant chord. The time each test method takes to execute determines the speed of the music. If more than one test class runs, then the music resolves to the tonic at the end of the session.

Here is the plugin (including source code). To try it out, simply save the .jar file in Eclipse's plugins directory and restart Eclipse. I tested it in Eclipse version 3.4.0 running on JDK 6. The plugin requires MIDI, so if you do not hear any sound when running JUnit tests, your computer probably lacks an appropriate MIDI device or it is configured incorrectly. Try running this simple class to test your MIDI setup.

I am not the first to think of making JUnit play music. There is a Musical JUnit project on SourceForge, but it has not been updated in three years. It also uses prewritten samples, while mine produces sound programmatically.

Update Thursday, February 25, 2010

I posted the code on BitBucket.


Jevon Says:

Haha this is great! I wanted a plugin to play a sound once a test case had finished; this is even better. Some ideas:

1. I don’t think the notes are being turned off at all. Some time after the tests are finished, you can still hear a very faint sound in the background.

2. Is there any chance of getting a preference page for the plugin, perhaps to change the default volume?

3. Perhaps an Eclipse update site? Would you be interested in putting this onto Google Code or likewise?

Brett Says:

Thanks for your comments, Jevon.

1. You’re right. The patch I was using naturally fades out, but it would be better if the plugin turned notes off explicitly.

2. A preference page would definitely be useful, not only for volume, but for things like the default key, the note progression in the arpeggio, or MIDI device settings.

3. An update site would also be useful, but it seemed like overkill for such a simple plugin.

The source code is bundled with the plugin, so you or anyone else are welcome to add features like those you list. If there is interest, I would be more than happy to post the code somewhere.

Leave a Comment

Allowed Tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>