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?

2 Answers 2

5

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

3

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

2
  • 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? Commented Jun 30, 2016 at 16:06
  • Thank you, it's a good idea not separate test ns discovery from unrelated concerns Commented Oct 10, 2021 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.