Unit testing for the Vim text editor.

View on GitHub


VimUnit is a unit testing library that lets you easily test vimscript. Its goal is to be simple to use and provide good, useful error messages. 'In Editor' testing as well as command line testing are supported.


Suppose you are working with a new plugin/script, and you're stuck. Something isn't working:


You notice that whenever you use the function sometimes it doesn't return anything. Whats going on? Fire up Vim and write up a test:


To run the tests you can use Vim's built-in quickfix commands. Type :make. Your test cases are automatically executed in their own sandbox (an instance of Vim) and are navigable via :cn, :cl and the like. You can run your tests via the command line, or in the editor (but its not recommended). See vim help docs for more information.


File: test.vim

Failure: TestGreater (assertions 0)
  31_MsgSink|offset 9| 'VU VUAssertTrue: arg1=0!=1'
  VUAssertTrue|offset 11|            call s:MsgSink('VUAssertTrue','arg1='.a:arg1.'!='.TRUE())
  TestGreater|line 8|fun example#diff(a,b)
Passed: 1 (1 assertions) Failed: 1, Exceptions: 0

Clearly something isn't right. Splitting out the test cases helps isolate the problem:


File: atest.vim

Failure: TestGreater (assertions 1)
  30_MsgSink|offset 9| 'VU AssertEquals: arg1=-1!=1'
  VUAssertEquals|offset 18|^I^Icall s:MsgSink('AssertEquals','arg1='. arg1text .'!='. arg2text . msg)
  TestGreater|line  10|  call VUAssertEquals(example#diff(2,3),1)
Passed: 1 (2 assertions) Failed: 1, Exceptions: 0

Ah ha! The second assertion returns -1 != 1...we need to be positive/negative number aware. A simple fix to test.vim and all the tess pass:

Command Line:

File: atest.vim
Passed: 2 (3 assertions) Failed: 0, Exceptions: 0



Pathogen makes it pretty easy to do plugin installation. Ensure pathogen is installed and configured and then use git to checkout this:

Command Line:
git clone ~/.vim/bundle/vimunit


Vundle is my preferred installation method as it makes it very easy to add/remove plugins. Edit your .vimrc file and update your plugins:

Bundle 'dsummersl/vimunit'
In Vim:


For more documentation type :help vimunit in your vim editor.

Support or Contact

Found a problem? Open a ticket on the github page.