BDD test naming with AutoHotKey

Updates: See change log at the bottom of this post for the most recent updates.

Update 2008-05-29: JP has posted a much better version of this script (with suggestions from a few of his readers). I’ve updated the script on this post to work more like JP’s version, but you’re probably best off grabbing it from his post, or searching his site for his latest version.

Was having a chat earlier with my good mate JP Boodhoo… er, well, more accurately, I left a comment on his blog and he was nice enough to email me back. Anyway, JP has started trying AutoHotKey rather than his previous macro for BDD-style test naming.

I thought I’d post an extremely over-engineering version of this AutoHotKey script, which has a toggle-approach similar to the Emacs Everywhere script I posted earlier.

Once you have AHK installed, you can just extract the ZIP below and double click the .AHK file to load the script. The script will let you toggle "test-naming mode" (i.e. replacing spaces with underscores) using Ctrl + Shift + U. You can cancel out of test naming mode by pressing ENTER, ESCAPE, TAB, starting the method signature by typing a ‘(‘, or typing a ‘{’ or ‘:’ for when you are naming a class. Pressing Ctrl + Alt + U will insert a new test template before switching on test naming mode (although you might be better off using R# templates for this). All this is simply to make it easier to type out tests like this:

public void Test_naming_mode_turns_spaces_to_underscores() {}

Version 2.2 of the script can be downloaded here:

Feel free to change the hotkeys and the dodgy icons :). I haven’t had a good test of it yet so use at your own risk.

If you’re happy with how it works you can add it to your Startup programs and have BDD-style test naming goodness whenever you like. Hope_this_helps! :-)

Change log

  • 2008-11-18: Uploaded v2.2, making TAB exit test naming mode. This is helpful when using Resharper live templates for tests.
  • 2008-08-13: Uploaded v2.1, making ‘{’ and ‘:’ exit test naming mode, based on Scott C Reynold’s script modification. I should probably make it exit on any punctuation, but calling YAGNI on it for now.
  • 2008-05-29: Uploaded v2, synching with JP’s version 2, adding test templates, and made test mode exit after typing ‘(’ for test method signature
  • 2008-05-28: Updated hotkeys to match JP’s version
  • 2008-05-28: Original post