Writing JUnit Test PluginsWriting a test plugin is no different from writing a regular plugin. After creating your test plugin, simply creating test cases the usual junit way by extended org.junit.TestCase. Note: The junit library is bundled as the org.junit plugin. Your test plugin must depend on it.
Naming ConventionsThe naming convention for plugins is [namespace].[major subsystem].[minor subsystem]. Examples include: the feature.xml file net.refractions.udig.catalog net.refractions.udig.catalog.wfs net.refractions.udig.project net.refractoins.udig.project.ui The naming convention for test plugins is [namespace].[major subsystem].tests.[minor subsystem]. Examples include: net.refractions.udig.catalog.tests net.refractions.udig.catalog.tests.wfs net.refractions.udig.project.tests net.refractoins.udig.project.tests.ui Running Tests in the IDEAfter creating a test case in your new test plugin, right click on the class while in the Java perspective, and the context menu should contain a menu item entitled Run As -> JUnit Plug-in Test. This will start an eclipse runtime environment and run your test class. Running Automated TestsIn order to have your test plugin run with the rest of the automated test plugins, the following steps must be taken:
Creating a Test SuiteA test suite is a java class which extends junit.framework.TestSuite. Each test class you write must be added to the test suite. The following is an example of a test suite which contains three test classes. public class CatalogUITestSuite extends TestSuite { /** Returns the suite. This is required to use the JUnit Launcher. */ public static Test suite() { return new CatalogUITestSuite(); } public CatalogUITestSuite() { addTest(new TestSuite(HeadlessWizardDialogTest.class)); addTest(new TestSuite(BasicDataPipelineTest.class)); addTest(new TestSuite(BasicDataPipelineDialogTest.class)); } }
Creating the test.xml Script.The test.xml file is an ant build script which runs your unit tests. The following is a template test.xml of such a script. Located near the top of the file are three properties which must be modified to reflect your particular test plugin. The properties include:
Adding the Plugin to the net.refractions.udig.test FeatureThe easiest way to add a plugin to a particular feature is using the eclipse feature editor.
Adding the Plugin to the Automated Test SetTo add the plugin to the automated test set, you must check out http://svn.geotools.org/udig/trunk/scripts. This directory contains two files that must be modified.
test.propertiesThis file contains a list of properties which map a test plugin name to an id,version tuple and looks as follows: org.eclipse.test=org.eclipse.test_3.1.0 net.refractions.udig.catalog.tests=net.refractions.udig.catalog.tests_1.0.0 net.refractions.udig.catalog.tests.wfs=net.refractions.udig.catalog.tests.wfs_1.0.0 net.refractions.udig.project.tests=net.refractions.udig.project.tests_1.0.0 net.refractions.udig.project.tests.ui=net.refractions.udig.project.tests.ui_1.0.0
To add the catalog.tests.ui plugin, we would add the following property: net.refractions.udig.catalog.tests.ui=net.refractions.udig.catalog.tests.ui_1.0.0 test.xmlThis file is the root ant test script. It runs tests by delegating to the test.xml script created above. In order to have to the root script call your test.xml script, you must modify the target named all and add a call to your target. The all target is located near the bottom of the script and looks like the following: <target name="all"> <antcall target="catalog" /> <antcall target="catalog.wfs" /> <antcall target="project" /> <antcall target="project.ui" /> </target> To add the catalog.tests.ui plugin, we add the following line: <antcall target="catalog.ui" /> The final step is to add a target which matches the name above.
The following is an example of a target: <target name="catalog.ui"> <antcall target="runtests"> <param name="testPlugin" value="${net.refractions.udig.catalog.tests.ui}"/> <param name="report" value="net.refractions.udig.catalog.tests.ui"/> </antcall> </target> The target can be added anywhere in the file.
Note that the plugin required to run automated tests is "eclipse-test-framework-3.1.zip", available here: ![]() ![]() ![]() ![]() ![]() |
(c) Copyright (c) 2004,2005 Refractions Research Inc. and others. |