Unit testingΒΆ

Unit testing of code that uses the Javabridge requires special care because the JVM can only be run once: after you kill it, it cannot be restarted. Therefore, the JVM cannot be started and stopped in the regular setUp() and tearDown() methods.

We provide a plugin to Nose that takes care of starting and stopping the JVM. The plugin’s name is javabridge.noseplugin. Installing the Javabridge adds the plugin to Nose.

To use the plugin for your own project, in the [nosetests] section to your setup.cfg, add with-javabridge = True. You can also specify a classpath; the jar files required for javabridge to function (javabridge.JARS) will be added to this path:

with-javabridge = True
classpath = my-project/jars/foo.jar

You should then be able to run the nosetests command:


On some installations, setuptools’s nosetests command will also work:

python setup.py nosetests

If you prefer, these options can also be given on the command line:

nosetests --with-javabridge=True --classpath=my-project/jars/foo.jar


python setup.py nosetests --with-javabridge=True --classpath=my-project/jars/foo.jar