2

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

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

当我使用 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 文件中的肯定配置:

<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>
4

1 回答 1

10

看看这个使用 TestNG 的 Maven站点。

基本上你所要做的就是向 TestNG 添加一个依赖项。

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

默认包括maven-surefire-plugin

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

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

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

于 2012-10-02T13:59:22.650 回答