Pages

Monday, February 10, 2014

TestNG dependsOnMethods example


Sometimes, you may need to invoke methods in a Test case in a particular order or you want to share some data and state between methods. This kind of dependency is supported by TestNG as it supports the declaration of explicit dependencies between test methods.
TestNG allows you to specify dependencies either with:
  • Using attributes dependsOnMethods in @Test annotations OR
  • Using attributes dependsOnGroups in @Test annotations.

public class MessageUtil {
    private String message;

    // Constructor
    // @param message to be printed
    public MessageUtil(String message) {
        this.message = message;
    }

    // prints the message
    public String printMessage() {
        System.out.println(message);
 return message;
    }

    // add "Hi!" to the message
    public String salutationMessage() {
 message = "Hi!" + message;
 System.out.println(message);
 return message;
    }
}

No comments:

Post a Comment