Writing Java Unit Tests for Plugin Code
This tutorial assumes that you have a Maven project that implements a plugin for Oxygen XML Web Author.
For some unit tests, you need to create an AuthorDocumentModel, which is the
server-side model for an XML document that is open in the browser. For this, you need to use
the
ro.sync.ecss.extensions.api.webapp.WebappAuthorDocumentFactory.createAuthorDocumentInfo
method. However, this class has to be configured to run in a development mode by following
these steps:- You need to declare a dependency on
mockito-all
in the pom.xml file, like this:<dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> <scope>test</scope> </dependency>
- In the root folder of your project, you need to create a
test/fake_editor_home/frameworks/ folder and place all the
frameworks you want to use in tests in this folder. The Web Author's default frameworks
are available in the Oxygen Maven repository with the following
details:
<dependency> <groupId>com.oxygenxml</groupId> <artifactId>frameworks</artifactId> <version>${oxygen.version}</version> <type>zip</type> </dependency>
- Make sure to call
MockAuthorDocumentFactory.initForTests()
before any tests are run. For example, when using JUnit 4, you can run it in a method annotated with@BeforeClass
.