如何使用Maven POM文件运行testNG测试 [英] How to run testNG tests using Maven POM file

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

问题描述

我有一个使用Maven和TestNG的Selenium项目.

I have a Selenium project, using Maven and TestNG.

我尝试了几种不同的方法来使测试通过Maven命令运行(我使用的是肯定的fire插件). 当我运行Maven时,测试不会运行.没有错误.

I have tried several different methods of getting my tests to run with a Maven command (I'm using the sure fire plugin). When I run Maven the tests do not run. There are no errors.

在使用mvn测试时,有没有人提供一个很好的示例或教程来使我的测试得以运行?

Has anyone got a good example or a tutorial that I could follow to get my test to run when I use mvn test?

谢谢.

以下是输出:

C:\**************>mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - **************:**************:jar:1.0
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\**************\src\test\res
ources
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Oct 02 15:14:10 BST 2012
[INFO] Final Memory: 16M/38M
[INFO] ------------------------------------------------------------------------

以及我的POM文件中的surefire配置:

And the surefire configuration from my POM file:

<plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>iso-8859-1</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/main/test_suites/local/***_Test.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

推荐答案

看看这个基本上,您要做的就是向TestNG添加一个依赖项.

Basically all you have to do is adding a dependency to the TestNG.

<dependencies>
  [...]
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.3.1</version>
      <scope>test</scope>
    </dependency>
  [...]
</dependencies>


maven-surefire-plugin中的默认值包括:


The default includes in maven-surefire-plugin are:

<includes>
    <include>**/Test*.java</include>
    <include>**/*Test.java</include>
    <include>**/*TestCase.java</include>
</includes>

这意味着,如果您的测试类的名称与上述包含模式不匹配,则maven-surefire-plugin将找不到它们并运行它们.

That means that if the name of your test classes does not match the above include patterns then maven-surefire-plugin will not find them and run them.

您可以通过将这些文件添加到插件配置中来更改/添加文件.

You can change/add files to include by adding these to the plugin configuration.

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

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