Introduction

This section discusses ways to write custom functional points in a generic way. These basic concepts and practices should be applicable to all plug-ins.

Jameleon does not require you to write your own functional points. However, there are many benefits to writing a functional point for each screen or feature in your application. Having a function tag that represents a feature of the application helps make the script more readable and also helps when creating new scripts. With a pre-defined set of application-specific tags, one can quickly create a test without having to understand the low-level specifics of what it took to automate that specific feature. It turns several steps required to actually automate the feature into one simple step.

Using application-specific tags to test functional areas can save time when a feature in the application changes. If you have several test scripts that test this feature using generic tags, you would need to update each script that tests the modified feature. With custom tags, one can simply change the behavior of the tag to match the changes in the application. Now all the test scripts that use the custom tag will function properly again.

How to Write a Custom Functional Point

Writing a custom tag is simple and powerful. Please see the Function Points section for detailed instructions on writing custom function tags.

If you are using the jameleon-test-suite-x.x.x.zip distribution, then place your custom tags in the jameleon-test-suite/src/java directory. To build custom tags, simply open a command prompt to the jameleon-test-suite folder and type build under windows or ./build.sh under *nix.

Example Function Tags

Simple Tag

Our first example is the source to the ju-assert-equals tag. Notice how msg isn't required. If it is set, then we call the assertEquals method that will print out the provided error message or msg if a failure occurs. Otherwise, it will call the assertEquals method without a failure message.

package net.sf.jameleon.plugin.junit.tags;

import net.sf.jameleon.plugin.junit.JUnitFunctionTag;

/**
 * Performs an assertEquals on two strings.
 * @jameleon.function name="ju-assert-equals" type="action"
 * @jameleon.step Compare the expected value against the actual value.
 */
public class AssertEqualsTag extends JUnitFunctionTag{

    /**
     * The expected value
     * @jameleon.attribute
     */
    protected Object expected;
    /**
     * The actual value
     * @jameleon.attribute
     */
    protected Object actual;
    /**
     * The error message to display if the test fails
     * @jameleon.attribute
     */
    protected String msg;

    public void testBlock(){
        if (msg != null) {
            assertEquals(msg, expected, actual);
        }else{
            assertEquals(expected, actual);
        }
    }

}
                        

Making an Attribute Required

Let's say you didn't want to the do the logic yourself and you wanted the function tag to fail if the user didn't provide the msg attribute. We would change the above example to the code below.

package net.sf.jameleon.plugin.junit.tags;

import net.sf.jameleon.plugin.junit.JUnitFunctionTag;

/**
 * Performs an assertEquals on two strings.
 * @jameleon.function name="ju-assert-equals" type="action"
 * @jameleon.step Compare the expected value against the actual value.
 */
public class AssertEqualsTag extends JUnitFunctionTag{

    /**
     * The expected value
     * @jameleon.attribute
     */
    protected Object expected;
    /**
     * The actual value
     * @jameleon.attribute
     */
    protected Object actual;
    /**
     * The error message to display if the test fails
     * @jameleon.attribute required="true"
     */
    protected String msg;

    public void testBlock(){
        assertEquals(msg, expected, actual);
    }

}
                         
Now you know that msg will be set so there is no need to validate that it has been set.