Over a million developers have joined DZone.
Platinum Partner

Functional Tests in a Maven-Based NetBeans Platform Application

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

Let's create a Maven-based application on the NetBeans Platform and set up some functional tests. So, we will create an automated test environment for the UI of our application. The starting point for these kinds of tests is to design a few typical scenarios that your end users are going to step through in their day-to-day work with your application. Then, you need to create functional tests that will simulate those typical scenarios.

Fortunately, the NetBeans Platform comes with a package that extends JUnit, named org.netbeans.junit, with a lot of helpful test-related support classes. Specifically for functional testing, there's the org.netbeans.jellytools package. Let's use the latter to set up our functional tests.

  1. Install NetBeans IDE 7.0 Beta or above.

  2. Create a new Maven-based NetBeans Platform application via the related template in the IDE.

  3. Open the POM file of the application, where you will find some sections that have been commented out. Remove the comment-out lines and you will end up with these dependencies in the application POM:

  4. You will also have the SureFire section included, in the "build" section of the application POM, again by removing the line that comments the section below out:

  5. In one of the module's of your application, do some stuff:
    public class DoStuff {
        public static void stuff(String label) {
            TopComponent tc = new TopComponent();

    Note: The above code comes from Jesse's attachment in the issue about functional testing for Maven-based NetBeans Platform applications.

  6. Now create a new test in the application's "src/java/test" folder, as follows:
    import junit.framework.Test;
    import org.netbeans.jellytools.JellyTestCase;
    import org.netbeans.jellytools.OptionsOperator;
    import org.netbeans.junit.NbModuleSuite;
    public class FuncTest extends JellyTestCase {
        public static Test suite() {
            return NbModuleSuite.allModules(FuncTest.class);
        public FuncTest(String n) {
        public void testWhatever() throws Exception {

    Via the org.netbeans.jellytools.OptionsOperator, you gain access to the Options window in your application.

  7. Right-click the application, choose Test, and then your tests will start up. The application starts, a new window is created (with "hello" as the display name), the "Miscellaneous" tab of the Options window is opened, there's a thread sleep, and an OK message.

    You'll see the result in the IDE. If you get stuck setting up the above scenario, here's a screenshot of everything:

Documentation on all the various operators are found in the NetBeans Javadoc for the Jelly Tools Platform:



The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}