In This Topic
The XperienCentral test framework is based on JUnit. See the JUnit website for an introduction to the framework and documentation (for example on the use of "asserts’). A testbundle is an executable Java application that is used to test other parts of the application. A plugin developer can use this framework to create testbundles for the plugins the developer writes. The big advantage of testbundles is that they are very easily incorporated into the build process. The execution of the tests can be automated, which saves a lot of time testing the plugin’s functions. It also contributes to higher quality of the developed plugins.
Creating a Testbundle
Creating a blank testbundle is done based on an archetype, just like creating a basic element, panel, etc. The commands below are based on the directory structure as created in Quick Start.
To create a testbundle, follow these steps:
- Open a command prompt.
- Navigate to the directory in which you already created your helloworld plugins (
- Enter the command (replace
<XperienCentral Version>with the version number of XperienCentral that you’re building against, (10.10.0, for example):
mvn archetype:generate -DinteractiveMode=false -DarchetypeGroupId=nl.gx.webmanager.archetypes -DarchetypeArtifactId=XperienCentral-testbundle-archetype -DarchetypeVersion=<webmanager version> -DgroupId=com.gxXperienCentral.helloworld -DartifactId=helloworldtestbundle -Dclassprefix=HelloWorld -s ..\XperienCentral9\settings.xml
A new folder called “helloworldtestbundle” is created
Building and Deploying the Testbundle
To build and deploy the testbundle, follow these steps:
- Open a command prompt.
- Navigate to the folder
- Execute the command:
mvn -s ..\..\XperienCentral\settings.xml clean package
- Copy the file
helloworldtestbundle-1.0.0.jarfrom the “target” directory to
Running the Testbundle
The testbundle is now deployed in the XperienCentral release. The easiest way to run the test it is from the Tomcat console. In order to run this test from the console, a few extra bundles need to be present. Therefore, copy the following bundles to
After adding these JAR files to the
/deploy directory, enter the following command in Tomcat:
The result will be the following lines in the Tomcat log:
Adding Tests to the Default Testbundle
To add tests to the testbundle, only one file needs to be extended:
CustomTest.java By default,
CustomTest.java looks like this:
The JUnit framework will process the methods in the following order:
- Run the
- Run all methods that start with "test" - the order in which they will be processed is not fixed.
- After running the tests, the method
tearDownwill be called.
Accessing the XperienCentral API from the Testbundle
To access the XperienCentral APIs, the authorization needs to be set correctly. Typically, the authorization needs to be in place for all the tests that will be run from the testbundle, therefore it is recommended that you make the XperienCentral session object available to all the tests by using private class members. A testbundle that needs XperienCentral authorization will typically look like this:
Using the Spring Mock Framework
XperienCentral integrates the Spring mock classes to make it more convenient to write JUnit testbundles. For example, this can be used to emulate a request and response. More information about Spring mock can be found at junit.org.