简体   繁体   English

如何使Maven使用我的TestNG XML文件?

[英]How to get Maven to use my TestNG XML file?

**FIRST: I have read literally every post in here on how to do this, I am following all instructions to the letter including those from Maven itself. **第一:我已经阅读了这里的每篇文章,了解如何执行此操作,我正在遵循这封信的所有说明,包括来自Maven本身的说明。

I have converted an Eclipse Selenium project using TestNG over to a Maven project. 我已经将使用TestNG的Eclipse Selenium项目转换为Maven项目。 I cannot get Maven to run my tests from the Test.XML file instead of running in the default mode where it just picks up anything with the word "Test" in the file name... I can execute the test.xml directly and everything works, so I think I got the conversion right. 我无法让Maven从Test.XML文件运行我的测试,而不是在默认模式下运行,在默认模式下,它只会选择文件名中带有单词“ Test”的任何内容...我可以直接执行test.xml可以,所以我认为转换正确。 Since I am converting from an existing framework the effort required to switch everything to work with the default "just grab anything called 'test'" is prohibitive, I want my Test.XML file to be used by SureFire. 由于我是从现有框架转换而来,因此将所有内容切换为使用默认的“仅抓取称为'test'的任何东西”所需的工作量是令人望而却步的,我希望SureFire使用我的Test.XML文件。

I am new to Maven so forgive my not using right terms but: when I 'run' the POM file with the 'goal' of TEST it simply ignores my test.xml file and runs anything with the word "test" in it, i verified this by changing names etc... I am running from Eclipse mostly, same results the few times I tried command line. 我是Maven的新手,所以请原谅我使用的术语不正确,但是:当我以“目标”的“目标”“运行” POM文件时,它只是忽略了我的test.xml文件,并在其中运行带有“ test”一词的任何内容,我通过更改名称等方式验证了这一点。。。我主要是从Eclipse运行,几次尝试命令行时都得到了相同的结果。

Here is my POM: 这是我的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>TestSuite</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>TestSuite</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/test.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.35.0</version>
        </dependency>
    </dependencies>
</project>

If you need more information let me know I will amend but my TestNG file literally just calls one test class no frills and it works if I execute it directly as a testNG test. 如果您需要更多信息,请告诉我,我将进行修改,但是我的TestNG文件实际上只是调用一个测试类,没有多余的装饰,并且如果我直接将其作为testNG测试执行,则它可以工作。 Rest of the code works so I am assuming it's not that. 其余代码可以正常工作,所以我假设不是那样。 Maybe a setting in Eclipse? 也许是Eclipse中的设置?

I cannot get Maven to run my tests from the Test.XML file instead of running in the default mode where it just picks up anything with the word "Test" in the file name. 我无法让Maven从Test.XML文件运行测试,而不是在默认模式下运行,在默认模式下Maven只会选择文件名中带有单词“ Test”的任何内容。

That is probably because of the Maven Surefire Plugin's default inclusion patterns : 这可能是由于Maven Surefire插件的默认包含模式

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns: 默认情况下,Surefire插件将自动包含具有以下通配符模式的所有测试类:

"**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test". “ ** / Test * .java”-包括其所有子目录以及以“ Test”开头的所有Java文件名。 "**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test". “ ** / * Test.java”-包括其所有子目录以及所有以“ Test”结尾的Java文件名。 "**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase". “ ** / * TestCase.java”-包括其所有子目录以及所有以“ TestCase”结尾的Java文件名。

And, as you know, "Suite XML Files configuration will override the includes and excludes patterns and run all tests in the suite files." 而且,正如您所知,“ Suite XML Files配置将覆盖包含和排除模式,并在套件文件中运行所有测试。”

I cannot tell for sure, but it looks like there are some troubles with reading the test.xml file (file is not found, parsing, encoding issue, etc) and Surefire falls back to the inclusion/exclusion policies. 我不能肯定地说,但是看起来似乎在读取test.xml文件时遇到了一些麻烦(找不到文件,解析,编码问题等),Surefire退回了包含/排除策略。

You may do a little test to prove this. 您可以做一些测试来证明这一点。 Add 'includes' and/or 'excludes' sections inside 'configuration' and exclude all classes except random one. 在“配置”中添加“包含”和/或“排除”部分,并排除除随机类之外的所有类。 If that random class is run, then the 'suiteXmlFiles' is simply ignored. 如果运行该随机类,则仅忽略“ suiteXmlFiles”。

Hope this will narrow down the scope. 希望这会缩小范围。

The groupid is incorrect. 组ID不正确。 You are missing an s in the plugin. 您在插件中缺少。 It should be <groupId>org.apache.maven.plugins</groupId> 它应该是<groupId>org.apache.maven.plugins</groupId>

I think what is happening because of this is maven is defaulting to it's default test phase config and ignoring yours. 我认为正在发生的事情是因为Maven默认使用默认的测试阶段配置,而忽略了您的配置。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有 testng.xml 文件的情况下执行 Testng 和 Maven - How to execute Testng and Maven without testng.xml file 如何从批处理为maven项目运行testng .xml文件 - How to run a testng .xml file from batch for a maven project 对 TestNG version# 和 Selenium-JAVA version# 感到困惑 - 如何获取 Maven POM.xml 文件的版本号 - Confused about TestNG version# and Selenium-JAVA version# - How to get version number for Maven POM.xml file 如何从 Maven 运行 testng.xml? - How to run testng.xml from Maven? 如何告诉Maven和TestNG运行特定的测试类或suite.xml文件? - How do I tell Maven and TestNG to run either a specific test class or a suite.xml file? 如何从Maven命令将特定的测试方法名称传递到testng.xml文件 - How to pass particular test method name to testng.xml file from maven command 如何使用Maven在TestNG套件xml文件中的多个类中运行测试类? - How to run a test class from multiple classes in a TestNG suite xml file using maven? Maven 不运行我的 testng.xml - Maven doesn't run my testng.xml 在Maven 3.5.2中,如何使用pom.xml文件中settings.xml文件中定义的配置文件? - In Maven 3.5.2, how do I use a profile defined in my settings.xml file in my pom.xml file? 从 Maven 测试运行时,testng.xml 不是有效文件 - testng.xml is not a valid file when running from Maven Test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM