tl;dr Keyboard shortcuts make Clojure TDD quick ’n’ easy.
Cursive is a plugin for IntelliJ’s IDEA that provides a wonderful environment for writing Clojure.
One of the ways it plugs into the IDE doesn’t show up until you’ve configured a REPL. Once your REPL is up and running, you can click in the menu bar’s Tools sub-menu, and then into the Clojure REPL option. If you’re in a test namespace, you’ll see a few test-specific options.
These great tools can be made even greater by binding some keyboard shortcuts to them. Since setting that up wasn’t immediately clear to me, I thought I’d share some notes about it.
First, open the preferences window with
Second, select the Keymap section.
Third, duplicate one of the default keymaps. On my laptop, I picked Default for macOS. To duplicate it, click the gear icon next to the dropdown and click Duplicate… and give it a name; I called my custom keymap, creatively, “Dan”. (In actual use, that is; the astute reader may observe it’s actually “Pants” in the screenshot below.)
Step four finally gets interesting, because it’s time to actually set up the keyboard shortcuts. IntelliJ has an awful lot of behaviors available, so you’ll likely want to use the filter menu; repl is a good search term.
From there, you’ll want to scan for the same items that appear in the tools menu. Right click each item, and select Add Keyboard Shortcut. This is your computer, so do what feels good, but here’s how I like to set it up.
Since IntelliJ allows you to add a “second stroke” to your keyboard shortcuts,
I take the opportunity to “namespace” my keyboard shortcuts under
Then I set up a second stroke for each of the three actions:
⌥-T R: Run Tests in Current NS in REPL. The mnemonic is “Run tests”. (’Cause R is right next to T on my keyboard, and this is the action I usually start with.)
⌥-T C: Run Test Under Caret in REPL. The mnemonic is “Caret”.
⌥-T T: Re-Run Last Test Action in REPL.
That last one is where the magic is.
Since it’s not uncommon for me to do a bit of test-driven development,
I can start by kicking off a failing test run with either
⌥-T R or
as I iterate toward working code,
I can tap
(❤️ that lightning-fast double tap)
and get rapid feedback.
- IntelliJ IDEA
- 2019.2.4 i(Community Edition)