endarkened
endarkened

Reputation: 41

running TestNG as an ant task causes an error

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?

Upvotes: 0

Views: 672

Answers (2)

endarkened
endarkened

Reputation: 41

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.

Upvotes: 0

Cedric Beust
Cedric Beust

Reputation: 15608

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?

Upvotes: 0

Related Questions