Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Write minimal requirement

jbdevstudioqajenkins edited this page Jun 23, 2015 · 72 revisions

Using minimal requirement simplify tests writing. It ensures that some action is done before a tests execution, e.g. clean workspace or open Java EE perspective. Thus, you can omit doing this actions from @BeforeClass methods. It's a powerful tool that provides cleaner code by using annotations.

Writing requirement

To define your own requirement, you have to define class and annotation. Class is fulfilling requirement and annotation is representing our action. Each annotation requirement class must implement Requirement interface. Creating requirement is described on simple example of creating requirement that will ensure that Console View is opened.

package org.jboss.reddeer.snippet.requirement;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jboss.reddeer.eclipse.ui.console.ConsoleView;
import org.jboss.reddeer.junit.requirement.Requirement;

import org.jboss.reddeer.snippet.requirement.OpenConsoleViewRequirement.OpenConsoleView;

/**
 * Requirement opening console view.
 */
public class OpenConsoleViewRequirement implements Requirement<OpenConsoleView> {

    private ConsoleView consoleView = new ConsoleView();

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    public @interface OpenConsoleView {

    }

    public boolean canFulfill() {
        //console view can be always open
        return true;
    }

    public void fulfill() {
        System.out.println("Opening console view.");
        consoleView.open();
    }

    public void setDeclaration(OpenConsoleView declaration) {
        //this annotation has no elements so we leave this method empty 
    }
    
    public void cleanUp() {
    	// nothing to do
    }
}

source code

Purpose of this example is just show how to create your own requirement. Requirements are useful when you are dealing with more complex actions like preparing database (e.g. creating tables and adding required records) or preparing server (e.g. adding and running server specified in user xml).

See also Requirements page and Test configuration page

Clone this wiki locally