Ⅰ. 插件描述
Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'eagletmt/tinytest'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'eagletmt/tinytest'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'eagletmt/tinytest'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/eagletmt/tinytest
Ⅳ. 文档说明
# tinytest
Usage
let s:unit = tinytest#new()
function! s:unit.setup()
let self.value = 1
endfunction
function! s:unit.teardown()
unlet self.value
endfunction
function! s:unit.test_plus()
call self.assert.equal(3, self.value + 2)
call self.assert.equal([1, 2, 3], [self.value] + [2, 3])
endfunction
call s:unit.run()- Create a tinytest object by
tinytest#new() Write test cases as a dictionary function whose name has
test_prefix- Special methods
setupandteardownare supported.
- Special methods
- Write assertions by asserter object
- Invoke
runmethod and the result is reported by reporter object
Mechanism
asserter
Asserter's methods should throw an exception prefixed with tinytest: if the assertion fails.
The default asserter is located at autoload/tinytest/asserter/default.vim.
reporter
A reporter object is hold by each test unit internally.
You cannot touch reporter object from test cases and asserters.
A reporter must have these methods:
on_startwill called when a test unit starts.on_case_startwill called each time a test case starts.on_case_successwill called each time a test case succeeds, i.e., no exceptions are thrown.on_case_failurewill called each time a test case fails, i.e., an exception prefixed withtinytest:is thrown.on_case_exceptionwill called each time a test case throws other exception.on_finishwill called when a test unit finishes.
Note that only one of on_case_success, on_case_failure and on_case_exception is called for each test case.
The default reporter echoes the result.
cli reporter writes the result to stdout.log file.
It is supposed to be used when you run tests from command line.
Design policy
Don't parse
Test cases should be written as an ordinal Vim script.
Parsing string arguments are evil.
Easy to change reporting format
- When you execute tests in Vim,
:echoor:call setline()to a special buffer would be suitable (default reporter). - When you execute tests from command line, reporting to a file and changing exit status according to the result would be useful (cli reporter).
Tiny
No very useful but complex functionalities.
License
Copyright (c) 2013, eagletmt