Table of contents
- Introduction (vim_lib)
- Plugin Manager without fatal flaws (vim_lib, vim_plugmanager)
- Project level and file system (vim_prj, nerdtree)
- Snippets and File Templates (UltiSnips, vim_template)
- Compiling and doing anything (vim-quickrun)
- Work with Git (vim_git)
- Deploy (vim_deploy)
- Testing with xUnit (vim_unittest)
- The library on which everything is kept (vim_lib)
- Other useful plugins
I have not had to work in companies that are testing their code as it should be done for subsequent maintenance and refactoring. In Russia, even large IT companies avoid the unit testing process, not to mention the system-wide one, which leads to tons of stale and petrified code. Yes, I think that the code under test is a quality code, but why do people avoid it? As I understand it, there are two reasons:
- Ignorance of testing methodologies and tools
- Difficulty in launching test cases
The first problem is beyond the scope of this article, but the second, especially for users of the Vim editor, I will try to solve here.
All the same versatility
If you read my
article about the vim_deploy plugin , then the
vim_unittest structure will seem familiar to you. This plugin is only a unified interface to access various utilities designed for unit testing. To work, he needs a specific adapter that will provide application logic for interacting with utilities. In practice, this means the following:
- You install vim_unittest and one or more adapters for it, such as vim_unittest_phpunit
- You use the vim_unittest commands or hotkeys to test a project or specific modules, and the utility that is configured for the current project will be completely transparent to the user.
In practice, this means that you can work with several projects at once and use the same commands (hotkeys) to test them, regardless of which testing utilities they use.
The vim_unittest and vim_deploy plugins are so similar that I even copied some of the text from the previous article, changing a couple of words. I apologize, of course.
Using
Consider an example of using this plugin with the vim_unittest_phpunit adapter. As mentioned above, you must first install vim_unittest and any adapter to work with testing utilities. You should also configure the testing utility, according to your requirements. In my case, these were the files:
phpunit.xml<?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="Bootstrap.php" backupGlobals="false" > <testsuites> <testsuite name="Test Suite"> <directory>./MyTest</directory> <directory>./DbTest</directory> </testsuite> </testsuites> </phpunit>
Bootstrap.php <?php define('IN_TEST', true); require_once '../init.php'; if(!defined('CURRENT_LANGUAGE')){ define('CURRENT_LANGUAGE', 'ru'); }
After you need to add the following settings to your
.vimrc file:
let g:vim_unittest
and create the tests themselves as separate files, for example:
ExampleTest.php <?php namespace Test; class ExampleTest extends \PHPUnit_Framework_TestCase{ public function testFirst(){ $this->assertTrue(1 == 1); } }
That's all. Three commands are used to run tests:
- UnitTestRun - run all project tests
- UnitTestRunFile - running tests in a specific file
- UnitTestRunCurrentFile - run tests in the current file
- UnitTestRunCurrentTest - test launch, on whose name the cursor is positioned (on the name of the testing class method)
Of course they are followed by zabindit and run one key.
The plug-in can not only run tests, but also displays the output of the utilities used in a separate window, and the adapters provide the value for the
errorformat option so that you can quickly navigate through the stack of calls that led to the error.
Bye all
Since most unit testing tools have a similar interface, they are easy to connect to vim_unittest. If you are not testing your code yet, do not take the time to do this, you will be thanked by those who will support it after you (or with you).