7

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?

Sam Estep
  • 449
  • 5
  • 20

2 Answers2

4

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."

Sam Estep
  • 449
  • 5
  • 20
3

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

Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
  • I like to version [my Emacs config](https://github.com/samestep/env/blob/master/emacs.el), 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 '21 at 08:01