如何使用Maven POM文件运行testNG测试

Lew*_*wis 2 selenium maven

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

我尝试了几种不同的方法让我的测试运行Maven命令(我正在使用确定的fire插件).当我运行Maven时,测试不会运行.没有错误.

当我使用mvn测试时,有没有人有一个很好的例子或教程可以让我的测试运行?

提前致谢.

这是输出:

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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

我的POM文件中的surefire配置:

<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>
Run Code Online (Sandbox Code Playgroud)

mab*_*aba 10

看看这个Maven使用TestNG网站.

基本上您所要做的就是为TestNG添加依赖项.

<dependencies>
  [...]
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.3.1</version>
      <scope>test</scope>
    </dependency>
  [...]
</dependencies>
Run Code Online (Sandbox Code Playgroud)

默认包括maven-surefire-plugin:

<includes>
    <include>**/Test*.java</include>
    <include>**/*Test.java</include>
    <include>**/*TestCase.java</include>
</includes>
Run Code Online (Sandbox Code Playgroud)

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

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