将 TestNG 作为 ant 任务运行会导致错误
当我尝试从 ant 运行 TestNG 作为“testng”任务时,我遇到了奇怪的行为。 TestNG 不会在 @BeforeSuite 方法中创建类实例,并且在 @Test 方法的子类中创建 NullPointerException。例如
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!
...
}
}
,当使用 ant 运行 TestNG 时,当尝试使用 TestNG lib 中的“taskdef”创建任务时,错误的堆栈跟踪显示 ant 类深处的某个地方,我才会得到该行为。 那么,这里有什么问题呢?这是一个错误还是我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能在调用或定义 ant 任务的方式上做错了。
你的build.xml是什么?什么是堆栈跟踪?
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?
知道了。问题出在 @BeforeTest 方法中。它不是在每个 @Test 方法之前调用,而是仅在标记中的第一个之前调用。如果我们将所有测试放在一个套件中 - 结果是可以预测的。
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.