Eclim's :JUnit command allows you to execute individual test or individual methods from your tests.
If you'd like to run a particular test you can do so by supplying the fully qualified class name of the test to run (you can use vim's tab completion here to alleviate having to type the full name):
Another way is to simply run :JUnit with no arguments and let it decide what to run based on the current context of the cursor:
If you'd like to run all tests for the current file, regardless of whether the cursor is on a method or not, you can do so by running :JUnit with the '%' argument:
For cases where you'd like to run all your unit tests you can run :JUnit with the '*' argument and eclim will locate all your test files and run them:
You can also pass in an ant compatible pattern to match the tests you'd like to run:
When editing a java file, if you would like to open the corresponding test, you can issue the command :JUnitFindTest. When the cursor is on a method in your source file this command will also try to find the corresponding test method within the test file.
If you run :JUnitFindTest from a test class, eclim will attempt to find the corresponding class that is being tested.
If you are running your unit tests from a build tool like ant or maven, then you most likely are writing those results to a directory in your project. If so then you can set the org.eclim.java.junit.output_dir setting to that location which then allows you to use the command :JUnitResult to locate and opening the result file for the currently open test or the test supplied as an argument.
While editing junit files, eclim provides functionality to generate test method stubs similar to the method override / impl functionality provided for non-test-case classes. The only difference is that instead of :JavaImpl, you use :JUnitImpl to open the window of possible methods to implement.
To determine what class the current test is for, eclim expects that the standard naming convention for tests is followed, where the test has the same fully qualified class name as the target class with a 'Test' suffix.
So for the test
org.foo.bar.BazTest, the exepected class being tested would
Eclim also supports tests with a 'Test' prefix instead of a suffix and in the case of neither a 'Test' prefix or suffix, it will search for a class of the same name in a different package should you perhaps use a package convention for your tests rather than a class name convention.
When invoking :JUnitImpl from within
org.foo.bar.BazTest, eclim will
locate the class
org.foo.bar.Baz and generate a list of methods to test
When you hit <enter> on the method to add, if that method belongs to a type in the hierarchy for the class being tested, then the corresponding test method stub will be inserted, otherwise a regular overriding stub will be generated.
org.eclim.java.junit.output_dir - Defines the project relative location of the junit test results.
org.eclim.java.junit.jvmargs - Json formatted list of strings to supply as args to the jvm when forking to run unit tests.
org.eclim.java.junit.sysprops - Json formatted list of strings to supply as system properties to the jvm when forking to run unit tests.
org.eclim.java.junit.envvars - Json formatted list of strings to supply as environment variables to the jvm when forking to run unit tests.
Currently eclim's support for TestNG is limited to supporting Vim's :make in conjunction with ant to populate vim's quickfix results with failed tests.
By default TestNG's output to the console is very terse. So in order to support monitoring of failed tests via vim's error format, eclim provides a custom TestNG listener which must be installed into your build environment.
The first step is to place the
eclim-testng.jar file in your TestNG
classpath you have configured for ant. You can find this jar file in your
The second step is to add the
listener attribute to your
testng task which references the required eclim testng listener:
... <testng ... listener="org.eclim.testng.TestNgListener"> ...
See the testng ant task docs for more information.
Once you have completed that setup, you should then be able to run your ant target from vim and (as long as eclim is running) all failed tests will be added to your vim quickfix results.
Ex. Assuming your ant task is named 'test':