(defun junit-get-tested-class-from-buffer() (let (result) (cond ((string-match "Test\.java\\(<.+>\\)?$" (buffer-name)) (setq result (substring (buffer-name) 0 (match-beginning 0)))) ((string-match "\.java\\(<.+>\\)?$" (buffer-name)) (setq result (substring (buffer-name) 0 (match-beginning 0))))) result)) (defun junit-run() (interactive) (let ((tested-class (junit-get-tested-class-from-buffer))) (if tested-class (setq compile-command (format "make %s.test" tested-class)) (setq compile-command "make retest")) (command-execute 'compile nil))) (defun junit-search-test-method() (let (result) (save-excursion (if (re-search-backward "^[ \t]*public[ \t]+void[ \t]+\\(test[^(]*\\)" (point-min) t) (setq result (buffer-substring (match-beginning 1) (match-end 1))))) result)) (defun junit-run-method() (interactive) (let ((test-method (junit-search-test-method))) (if test-method (progn (setq compile-command (format "make %s.test TEST_METHOD=%s" (junit-get-tested-class-from-buffer) test-method)) (command-execute 'compile nil)) (junit-run))))