如何使Maven使用我的TestNG XML文件? [英] How to get Maven to use my TestNG XML file?

查看:87
本文介绍了如何使Maven使用我的TestNG XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**第一位:我已经阅读了这里的每篇文章,了解如何执行此操作,我正在按照这封信的所有说明进行操作,包括来自Maven本身的说明.

**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.

我已经使用TestNG将Eclipse Selenium项目转换为Maven项目.我无法让Maven从Test.XML文件运行我的测试,而不是在默认模式下运行,在默认模式下,它只会拾取文件名中带有单词"Test"的任何内容...我可以直接执行test.xml可以,所以我认为我的转换正确.由于我是从现有框架转换而来,因此无法将所有内容切换为使用默认的仅抓取称为'test'的任何东西"需要进行大量工作,我希望SureFire使用我的Test.XML文件.

I have converted an Eclipse Selenium project using TestNG over to a Maven project. 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. 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.

我是Maven的新手,所以请原谅我使用的术语不正确,但是:当我以目标"的目标"运行" POM文件时,它只是忽略了我的test.xml文件,并在其中运行带有单词"test"的任何内容它,我通过更改名称等来验证了这一点...我主要是从Eclipse运行,几次我尝试命令行时都得到了相同的结果.

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.

这是我的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>

如果您需要更多信息,请让我知道我将进行修改,但是我的TestNG文件实际上只是调用一个测试类,没有多余的装饰,并且如果我直接将其作为testNG测试执行,则它可以工作.其余的代码有效,所以我假设不是那样的.也许是Eclipse中的设置?

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. Rest of the code works so I am assuming it's not that. Maybe a setting in Eclipse?

推荐答案

groupid不正确.您在插件中缺少.它应该是<groupId>org.apache.maven.plugins</groupId>

The groupid is incorrect. You are missing an s in the plugin. It should be <groupId>org.apache.maven.plugins</groupId>

我认为由于这是Maven发生的事情,因此默认情况下使用默认的测试阶段配置,而忽略了您的设置.

I think what is happening because of this is maven is defaulting to it's default test phase config and ignoring yours.

希望有帮助.

这篇关于如何使Maven使用我的TestNG XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆