ZK Unit Testing Project - zunit

From Documentation
DocumentationSmall Talks2009MarchZK Unit Testing Project - zunit
ZK Unit Testing Project - zunit

Ryan Wu, Engineer, Potix Corporation
March 27, 2009
In ZK 3.6.1 or later (recommend)


About this article

This article is one of the unit testing series. The best approach to learn how to test ZK application is read them in order.
In previous articles, How to Test ZK Application with Seleniumand ZK Unit Testing, we have introduced how to test your ZK application.
But it's a little complicated to build the whole test project.

Thus, this time, we create a shortcut for ZK users. This will help you build up your test easily.

  1. zunit - A project directory that contains several batch and libraries which are need while testing.
  2. A new feature (A way to use ID as UUID for unit test purpose) which was suggested by John Yesberg before is ready in ZK 3.6.1 Freshly.



  • JDK (MUST 1.4 or later)
    Download JAVA
    Must set the JAVA_HOME to your environment parameter.
  • Apache Ant[1]
    You can download it from here.
    Extract it and set the ANT_HOME to your environment parameter.
  • Selenium Remote Control[2]
    Follow the steps here : Setting up the Selenium Remote Control.
    Start you Selenium RC Server
  • Download zunit project
    Follow the steps next paragraph.
  • Your test application
    Without this, you can't do any test. :)


After finishing the environment configuration, you can start the test by the following steps.

St selenium overview0.png

1.Create Project

zunit contains one folder and one batch file called createProject.bat.

createProject.bat ProjectName

Users can easily create a Test projects.
St seleniun create.PNG

2.Write Case

Follow this article and write a test class for your application(s).

We have introduced the IdGenerator before. That's a way to have fixed uuid of ZK page.

In ZK 3.6.1, we created a new feature, ZK will generate the id to html element if the component has it's own Id.

This feature is more convenient and much easier when "locating" the elements on the web page.

How to make id to uuid

Simply unmark the id-to-uuid-prefix in zk.xml, and you can define a prefix to you custom id.


if your case have included other ZUL page, you MUST add ${page} on it's prefix.

BTW, sure you can also use the IdGenerator together.



<?page id="mypage" title="Test Tree item"?>
	<label id="mylabel">this is a label</label>
<span class="z-label" z.zcls="z-label" id="_zid_mypage_mylabel">this is a label</span>

Assume your page is mypage, and the label is mylabel, you can locate it like following:

Some tricks about locator

By the way, there are so many components in ZK. If you want to test them, you'd better follow the "ways" we used.
for instance,

  • Type some words into the *box component :
    you must user Selenium.focus() then Selenium.type()".
  • Click the button (Default mold):
    you can get it to be located with "ButtenID!real".

It's more convenient to use the Firebug we introduced before to find the right elements.

3.Run Test

If you build (compile) your resource already, this step will ignore the compile progress and do start the junit test,
After that, it will create a junit report by using the junit-frames.xsl (XSLT stylesheet).


St seleniun run.PNG

4.View report

The report file index.html will be created automatically in the report directory.

St selenium report.PNG

Optional command

Clean Project

This option only used in some cases your file was already compiled and have some error or exceptions.
It will delete the build and report directory and recreate them.


St seleniun clean.PNG

Build Test

This process is only doing compile to all the java file in unittests directory.

  • Make sure all the library you need is already put into lib directory.

St seleniun build.PNG



  1. Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make's wrinkles.
  2. Selenium : Selenium Official Site


Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.