테스트 실행하기
CIDER 안에서 clojure.test
테스트를 빠르게 실행할 수 있습니다. 소스 버퍼나 REPL 버퍼에서
C-c C-t n 이나 C-c C-t C-n 키를 누르면 현재 네임스페이스에 관련된
테스트를 실행합니다. CIDER 테스트가 포함되어 있는 네임스페이스를 스스로 찾을 수 있습니다.
C-c C-t l 이나 C-c C-t C-l 키를 누르면 프로젝트에 로드된 모든 테스트를
실행 할 수 있고 C-c C-t p 이나 C-c C-t C-p 키로 프로젝트에 포함된
모든 테스트를 실행할 수 있습니다. (프로젝트에 all 네임 스페이스) 또 C-c C-t t 이나
C-c C-t C-t 키로 특정 테스트를 따로 실행 할 수도 있습니다.
All test commands are available in REPL buffers as well. There you can also use , to invoke some of the testing commands.
In the buffer displaying the test execution results (*cider-test-results*
)
you'll have a bit of additional functionality at your disposal.
Keyboard shortcut | Description |
---|---|
g | Run test at point. |
n | Run tests for current namespace. |
l | Run tests for all loaded namespaces. |
p | Run tests for all project namespaces. This loads the additional namespaces. |
f | Re-run test failures/errors. |
M-p | Move point to previous test. |
M-n | Move point to next test. |
t or M-. | Jump to test definition. |
d | Display diff of actual vs expected. |
e | Display test error cause and stacktrace info. |
Certain aspects of the test execution behavior are configurable:
-
If your tests are not following the
some.ns-test
naming convention you can customize the variablecider-test-infer-test-ns
. It should be bound to a function that takes the current namespace and returns the matching test namespace (which may be the same as the current namespace). -
If you want to view the test report regardless of whether the tests have passed or failed:
(setq cider-test-show-report-on-success t)
Running tests automatically (test-driven development)
CIDER provides a minor-mode that automatically runs all tests for a namespace
whenever you load a file (with C-c C-k). You can toggle it
manually with M-x cider-auto-test-mode
, or you can use:
(cider-auto-test-mode 1)
This is completely equivalent to manually typing C-c C-t C-n every time you load a Clojure buffer. Also, as described above before, CIDER is smart enough to figure out the namespace containing the tests.
Using cider-test with alternative test libraries
The clojure.test
machinery is designed to be pluggable. Any test library
can implement it if so desired, and therefore leverage cider-test
. For
instance, test.check does this, and
cider-test
handles defspec
just like deftest
.
As a test framework author, supporting the built-in clojure.test
machinery
(and hence cider-test
) is pretty straightforward:
- Assoc each test fn as
:test
metadata on some var. These are what get run. - Implement the
clojure.test/report
multimethod to capture the test results.
The test.check
library is a good example here. It was also designed completely
independently of clojure.test
. It just adds compatibility in this
namespace.