Creating and Running Automated Tests

If you have developed complex custom plugins and/or document types the best way to test your implementation and insure that further changes will not interfere with the current behavior is to make automated tests for your customization.

An Oxygen XML Editor standalone installation comes with a main oxygen.jar library located in the [OXYGEN_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:

  1. Create a new Eclipse Java project and copy to it the entire contents of the [OXYGEN_DIR].
  2. Add to the Java Build Path->Libraries tab all JAR libraries present in the [OXYGEN_DIR]/lib directory. Make sure that the main JAR library oxygen.jar or oxygenAuthor.jar is the first one in the Java classpath by moving it up in the Order and Export tab.
  3. Click Add Library and add the JUnit libraries.
  4. Create a new Java class which extends ro.sync.exml.workspace.api.PluginWorkspaceTCBase.
  5. Pass on to the constructor of the super class the following parameters:
    • 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.
    • String licenseKey The license key used to license the test class.
  6. Create test methods which use the API in the base class to open XML files and perform different actions on them. Your test class could look something like:
    public class MyTestClass extends PluginWorkspaceTCBase {
    	
    	/**
    	 * Constructor.
    	 */
    	public MyTestClass() throws Exception {
    		super(new File("frameworks"), new File("plugins"), 
            "------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-------");
    	}
    	
    	 /**
    	   * <p><b>Description:</b> TC for opening a file and using the 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());
    	  }
    }