In Cider, I can use C-c , to run the tests for the current namespace. This will work whether I'm currently in the source namespace or the test namespace itself (and indeed, this magic behavior is discussed in detail in the README).

Given that Cider already knows how to find the test namespace for a given source namespace (and I'd assume that finding the reverse is a similar problem), is there a function that I can use to quickly switch from a source buffer (e.g. src/example/core.clj) to its test buffer (e.g. test/example/core_test.clj) and vice versa?


Projectile provides a projectile-toggle-between-implementation-and-test function with exactly this behavior. As stated in the docs, you can use C-c p t to "Toggle between an implementation file and its test file."


Outside of Cider, there is toggle-test, which can switch between source and test buffers in a language agnostic way.

  • I like to version my Emacs config, so I don't want to pollute it with tgt-projects items. I was able to get it working by adding (put 'tgt-projects 'safe-local-variable #'listp) to my Emacs config and putting ((nil . ((tgt-projects . (((:root-dir "~/foo/bar") (:src-dirs "src") (:test-dirs "test") (:test-suffixes "_test"))))))) in the .dir-locals file for my project, but that seems pretty tedious. Is there a better way to set things up?
    – Sam Estep
    Jun 30 '16 at 16:06
  • Thank you, it's a good idea not separate test ns discovery from unrelated concerns
    – loevborg
    Oct 10 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.