【问题标题】:In which directory I have to place testng.xml?我必须在哪个目录中放置 testng.xml?
【发布时间】:2012-09-20 13:49:46
【问题描述】:

我正在做一个项目,我必须在其中执行自动化测试。为此,我使用了 Testng 框架。

我将testng.xml 作为输入文件,某些方法会消耗它,但是现在我的阅读器方法无法检测到该文件。

我在哪个目录中放置我的testng.xml 文件.....我必须在pom.xml 中制定任何 Maven 规范以检测testng.xml 文件是否存在并且他们必须阅读它。

【问题讨论】:

  • 你应该发布你的代码......你的问题在不知道你在做什么的情况下是没有帮助的......
  • 您能列出您用于构建的目录和 XML 文件吗?另外,当您引用文件时,您使用的是相对路径还是绝对路径?
  • 你读过documentation吗?
  • 如果有帮助记得采纳这个答案。

标签: java maven testng


【解决方案1】:

我将 testng.xml 文件放在哪个目录中.....

我怀疑testng.xml 文件应该放在类路径的顶部。如果您使用的是 maven,那么src/test/resources/testng.xml 就是一个好地方。看这个例子:

How to call testng.xml file from pom.xml in Maven

我必须在 pom.xml 中制定任何 maven 规范来检测 testng.xml 文件是否存在并且他们必须阅读它。

我对此不是 100% 确定的。在查看上面的示例时,建议使用以下内容:

<plugin>
    <groupId>org.apache.maven.plugin</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
    <configuration>
       <suiteXmlFiles>
           <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
       </suiteXmlFiles>
    </configuration> 
</plugin>

【讨论】:

  • 谢谢!这对我来说很好。但我注意到的最重要的一件事——无论放置什么文件夹 testng.xml,POM.xml 都应该完全替换它的位置。它有效:) 再次感谢。
【解决方案2】:

只要你在maven-surefire-plugin下的maven pom.xml中指定路径,放哪里都无所谓

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 2021-05-15
    • 1970-01-01
    • 2013-10-30
    相关资源
    最近更新 更多