如何在可执行 JAR 中加载 TestNG 配置?

发布于 2024-12-21 09:26:59 字数 574 浏览 4 评论 0原文

我有一个由 Maven 构建创建的阴影可执行 jar。在我的内部有一个主类,它执行并尝试运行一系列 TestNG 测试。它会一直运行,直到尝试加载用于测试的 xml 配置文件。主类中的步骤是:

    suites.add("testng-A.xml");
    suites.add("testng-B.xml");

    testng.setTestSuites(suites);
    testng.addListener(tla);
    testng.run();

问题是我无法让 TestNG 成功找到 xml 文件。我收到“java.io.FileNotFoundException:testng-a.xml(没有此类文件或目录)”错误。 JAR 中文件的位置是:

    /com/address/MyMainClass 
    /testng-a.xml
    /testng-b.xml

我正在使用以下命令运行 jar:

    java -jar uber.jar

关于如何让它工作的任何想法?

I have an shaded executable jar created by a Maven build. Within I have a main class that executes and attempts to run a collection of TestNG tests. It runs until it it attempts to load the xml config files for the tests. The steps within the main class are:

    suites.add("testng-A.xml");
    suites.add("testng-B.xml");

    testng.setTestSuites(suites);
    testng.addListener(tla);
    testng.run();

The problem is that I cannot get TestNG to successfully find the xml files. I receive a "java.io.FileNotFoundException: testng-a.xml (No such file or directory)" error. The location of the files in the JAR are:

    /com/address/MyMainClass 
    /testng-a.xml
    /testng-b.xml

I am running the jar with the following command:

    java -jar uber.jar

Any ideas on how I can get this to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

童话 2024-12-28 09:26:59

看来这不能在 JAR 中完成。 testng xml 配置无法以这种方式加载。加载之前,这些文件需要位于 JAR 外部。

http://groups.google.com /group/testng-users/browse_thread/thread/ad7e33342125e717?hl=en&pli=1

It looks like this cannot be done within the JAR. The testng xml configs cannot be loaded in this manner. The files need to be external from the JAR before loading.

http://groups.google.com/group/testng-users/browse_thread/thread/ad7e33342125e717?hl=en&pli=1

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