将 TestNG 作为 ant 任务运行会导致错误

发布于 2024-09-29 18:49:24 字数 618 浏览 0 评论 0原文

当我尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上得阳光 2024-10-06 18:49:24

您可能在调用或定义 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?

萤火眠眠 2024-10-06 18:49:24

知道了。问题出在 @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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文