Creating and Running Automated Tests
If you have developed complex custom plugins or document types, the best way to test your implementation and ensure that further changes will not interfere with the current behavior is to make automated tests for your customization.
An Oxygen XML Developer plugin standalone installation includes a main
oxygen.jar
library located in the [OXYGEN_INSTALL_DIR]
. That JAR library contains a
base class for testing developer customizations named:
ro.sync.exml.workspace.api.PluginWorkspaceTCBase
.
To develop JUnit
tests for your customizations using the Eclipse
workbench, follow these steps:
- Create a new Eclipse Java project and copy to it the entire contents of the
[OXYGEN_INSTALL_DIR]
. - Add all JAR libraries present in the
[OXYGEN_INSTALL_DIR]/lib
directory to the Java Build Path->Libraries tab. Make sure that the main JAR libraryoxygen.jar
oroxygenAuthor.jar
is the first one in the Java classpath by moving it up in the Order and Export tab. - Click Add Library and add the
JUnit
andJFCUnit
libraries. - Create a new Java class that extends
ro.sync.exml.workspace.api.PluginWorkspaceTCBase
. - Pass the following parameters on to the constructor of the super class:
File installationFolder
- The file path to the main application installation directory. If not specified, it defaults to the folder where the test is started.File frameworksFolder
- The file path to the frameworks directory. It can point to a custom frameworks directory where the custom framework resides.File pluginsFolder
- The file path to the plugins directory. It can point to a custom plugins directory where the custom plugins resides.File optionsFolder
- The folder that contains the application options. If not specified, the application will auto-detect the location based on the started product ID.String licenseKey
- The license key used to license the test class.int productID
- The ID of the product and should be one of the following:PluginWorkspaceTCBase.XML_AUTHOR_PRODUCT
,PluginWorkspaceTCBase.XML_EDITOR_PRODUCT
, orPluginWorkspaceTCBase.XML_DEVELOPER_PRODUCT
.
- Create test methods that use the API in the base class to open XML files and perform
various actions on them. Your test class could look something like
this:
public class MyTestClass extends PluginWorkspaceTCBase { /** * Constructor. */ public MyTestClass() throws Exception { super(null, new File("frameworks"), new File("plugins"), null, "------START-LICENSE-KEY------\n" + "\n" + "Registration_Name=Developer\n" + "\n" + "Company=\n" + "\n" + "Category=Enterprise\n" + "\n" + "Component=XML-Editor, XSLT-Debugger, Saxon-SA\n" + "\n" + "Version=14\n" + "\n" + "Number_of_Licenses=1\n" + "\n" + "Date=09-04-2012\n" + "\n" + "Trial=31\n" + "\n" + "SGN=MCwCFGNoEGJSeiC3XCYIyalvjzHhGhhqAhRNRDpEu8RIWb8icCJO7HqfVP4++A\\=\\=\n" + "\n" + "-------END-LICENSE-KEY-------", PluginWorkspaceTCBase.XML_AUTHOR_PRODUCT); } /** * <p><b>Description:</b> TC for opening a file and using a bold operation</p> * <p><b>Bug ID:</b> EXM-20417</p> * * @author radu_coravu * * @throws Exception */ public void testOpenFileAndBoldEXM_20417() throws Exception { WSEditor ed = open(new File ("D:/projects/eXml/test/authorExtensions/dita/sampleSmall.xml").toURL()); //Move caret moveCaretRelativeTo("Context", 1, false); //Insert <b> invokeAuthorExtensionActionForID("bold"); assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<!DOCTYPE task PUBLIC \"-//OASIS//DTD DITA Task//EN\" \"http://docs.oasis-open.org/dita/v1.1/OS/dtd/task.dtd\">\n" + "<task id=\"taskId\">\n" + " <title>Task <b>title</b></title>\n" + " <prolog/>\n" + " <taskbody>\n" + " <context>\n" + " <p>Context for the current task</p>\n" + " </context>\n" + " <steps>\n" + " <step>\n" + " <cmd>Task step.</cmd>\n" + " </step>\n" + " </steps>\n" + " </taskbody>\n" + "</task>\n" + "", getCurrentEditorXMLContent()); } }