tags:

views:

11

answers:

2

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?

A: 

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?

Cedric Beust
No, doing everything as described in here http://testng.org/doc/ant.html . It works ok when i do not pass instances from parent class to sibling, instantiating MainPage in Test_1 class.
endarkened
The problem might be, TestNG creates two different instances: one of TestBase to invoke @BeforeSuite and the other of Test_1 to perform @Test - the only explanation i see. Question to you as a developer of a framework.
endarkened