Edit online

Writing Java Unit Tests for a Framework Customization

Test-driven development enables great development speed because you can test changes without having to restart Oxygen XML Editor or Oxygen XML Web Author.

Another great advantage is that multiple developers can work on the project without fear of breaking things after each commit, because regressions are caught by the unit tests.

You can see how to write unit tests for an Oxygen Framework from our sample project that has a test that loads a sample framework, creates an AuthorDocumentModel from a sample document, and asserts its styles that are configured in the framework.

To write unit tests for a framework customization, follow this procedure (this same procedure was used for the sample project mentioned above):
  1. Add Oxygen SDK to the classpath and logback-classic (in our sample, they are added using Maven dependencies):
    <dependency>
      <groupId>com.oxygenxml</groupId>
      <artifactId>oxygen-sdk</artifactId>
      <version>${oxygen.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.10</version>
      <scope>provided</scope>
    </dependency>
  2. Before running a test, initialize Oxygen classes by running MockAuthorDocumentFactory.initForTest() and specify the location of the framework by specifying the "additional.frameworks.directories" option:
    Options.getInstance().setStringArrayProperty(
        "additional.frameworks.directories",
        new String[] {sampleFrameworkDir.getAbsolutePath()});
  3. In your test, load the AuthorDocumentModel using MockAuthorDocumentFactory.create(testFile).
  4. Use that AuthorDocumentModel object to access and assert classes in the Oxygen SDK.