1
votes

I have the two methods in a class UserRegistrationTest as given below. When i run class, the two methods ran successfully(UserRegistrationTest first then followed by userLoginSuccess). But when i want to debug the test userLoginSuccess alone, it is triggering the the UserRegistrationTest also. This is expected because I have dependsonMethods configured.

I am trying to find a way to nullify the dependsonMethods, when i do unit testing/debugging. I followed the trails given in the below links, but i couldnt able to finalize the solution.

https://groups.google.com/forum/#!topic/testng-users/K9lwhXuSLZM https://youtrack.jetbrains.com/issue/IDEA-141621

Please provide your thoughts.

Btw, I am able to nullify the dependsonMethods and dependsonGroups when i run as TestNg suite by giving the listner(IAnnotationTransformer). Also i am able to nullify by giving it in the pom.xml when running as maven test. But, when i run as TestNG Test, i am not able to set the dependsOnMethods to null programatically..

public class UserRegistrationTest {

        @Test(groups = { "userRegistration" })
    public void registerUserSuccess(ITestContext context) {
    ...
        context.setAttribute("user", user);
    }

     @Test(dependsOnMethods = { "userRegistration" })
    public void userLoginSuccess(ITestContext context) {
        User user = (User) context.getAttribute("user");
    ...
    }
}
1

1 Answers

0
votes

You can ignore any dependent method by defining : ignoreMissingDependencies = true

Method itself is saying,

enter image description here

public class UserRegistrationTest {

    @Test(groups = { "userRegistration" })
    public void registerUserSuccess(ITestContext context) {
    ...
        context.setAttribute("user", user);
    }

    @Test(dependsOnMethods = { "userRegistration" }, ignoreMissingDependencies = true)
    public void userLoginSuccess(ITestContext context) {
        User user = (User) context.getAttribute("user");
    ...
    }
}