Created
December 10, 2014 23:53
-
-
Save bahmanm/c11c94d2158eb1113879 to your computer and use it in GitHub Desktop.
Simple Maven + JUnit test runner for Emacs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; A quick way to run JUnit tests: | |
;;; `C-x t u` runs all the test cases in a unit. | |
;;; `C-x t c` runs a single test case. | |
;;; | |
;;; Simply add the snippet at the end of `init.el` or `.emacs`. | |
;;; NOTE: It assumes you are using projectile to manage the project. | |
;;; | |
;;; By Bahman Movaqar | |
;; runs all test cases in the current class | |
(defun run-test-unit () | |
(interactive) | |
(require 'imenu) | |
(let* ((file-name (buffer-file-name)) | |
(class-name (car (split-string | |
(car (last (split-string file-name "/"))) | |
"\\."))) | |
(root (projectile-project-root)) | |
(mvn-cmd (concat "cd " root " && " | |
"mvn -Dtest=" class-name " test "))) | |
(start-process "test-runner" | |
"test-runner" | |
"/bin/bash" | |
"-c" | |
mvn-cmd)) | |
(switch-to-buffer "test-runner")) | |
;; prompts for a single test case in the current class and runs it | |
(defun run-test-case () | |
(interactive) | |
(require 'imenu) | |
(let* ((file-name (buffer-file-name)) | |
(class-name (car (split-string | |
(car (last (split-string file-name "/"))) | |
"\\."))) | |
(test-case (car (imenu-choose-buffer-index "Test case: "))) | |
(root (projectile-project-root)) | |
(mvn-cmd (concat "cd " root " && " | |
"mvn -Dtest=" class-name "#" test-case " test "))) | |
(start-process "test-runner" | |
"test-runner" | |
"/bin/bash" | |
"-c" | |
mvn-cmd)) | |
(switch-to-buffer "test-runner")) | |
; key bindings | |
(global-set-key (kbd "C-x t u") 'run-test-unit) | |
(global-set-key (kbd "C-x t c") 'run-test-case) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment