Question

While I'm trying to run TestNG from ant as a 'testng' task, i'm getting strange behaviour. TestNG does not create class instance in @BeforeSuite method and in child classes in @Test method i'm getting NullPointerException. E.g.

public class TestBase {
    Page mainPage;

    @BeforeSuite
    public void login() {
        ...
        mainPage = new MainPage();
        ...
    }
}

public class Test_1 extends TestBase {
    @Test
    public void test1() {
        AlbumPage albumPage = mainPage.openAP(); //<-- here i get NullPointerException!
        ...
    }
}

That behaviour i get only if running TestNG using ant - stacktrace of the error shows origins somewhere deep in ant classes when it tries to create a task using 'taskdef' from TestNG lib. So, what is the problem here? Is this a bug or am i doing something wrong?

Was it helpful?

Solution 2

Got it. The problem was in @BeforeTest method. It is being invoked not before every @Test mehod but only before first in tag. If we pu all the tests in one suite - result is predictable.

OTHER TIPS

You're probably doing something wrong in the way you are invoking or defining the ant task.

What is your build.xml? What is the stack trace?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top