QuickRun のユニットテストのフック

昨日のポストの時点では Python の nose のみ対応していたが、色々追加した。
vim-quickrun-hook-unittest/autoload/quickrunex/unittest at master · heavenshell/vim-quickrun-hook-unittest · GitHub

  • PHP
    • Stagehand_TestRunner


それぞれのテスティングフレームワーク/ランナーにはテストメソッド/関数を指定できる。
Perl というか prove も対応したかったが、prove にはテストを指定して実行する機能がないよう。


vimrc に以下のように設定すれば実行できる。

" quickrun {{{
nnoremap <silent> <SPACE>r :QuickRun -mode n -runner vimproc:updatetime=10<CR>vnoremap <silent> <SPACE>r :QuickRun -mode v -runner vimproc:updatetime=10<CR>
nnoremap <silent> ,r :QuickRun -mode n -runner vimproc:updatetime=10 -hook/unitt
est/enable 1<CR>
augroup QuickRunUnitTest
  autocmd!
  autocmd BufWinEnter,BufNewFile *test.php setlocal filetype=php.unit
  autocmd BufWinEnter,BufNewFile test_*.py setlocal filetype=python.unit
  "autocmd BufWinEnter,BufNewFile test_*.py setlocal filetype=python.pytest
  autocmd BufWinEnter,BufNewFile *.t setlocal filetype=perl.unit
  autocmd BufWinEnter,BufNewFile *_spec.rb setlocal filetype=ruby.rspec
augroup END
let g:quickrun_config = {}
let g:quickrun_config['php.unit']    = {'command': 'testrunner', 'cmdopt': 'phpunit'}
let g:quickrun_config['python.unit'] = {'command': 'nosetests', 'cmdopt': '-v -s'}
"let g:quickrun_config['python.pytest'] = {'command': 'py.test', 'cmdopt': '-v'}
let g:quickrun_config['ruby.rspec']  = {'command': 'rspec', 'cmdopt': '-f d'}

Python の py.test を使用する場合は、コメントを外し、nosetest の方をそれぞれコメントする必要がある。


QuickRun でテストケースを全て実行するより、開発中は今かいてるテストケースを繰り返し実行する事で開発速度があがると思う。

あと自分が使うとしたら Node.js くらいか。
テスティングフレームワークどれがデファクトなんだろう。
# そのテストランナーがメソッド単位のテスト実行機能を提供しているのが大前提だけど…。