我有一个使用 Maven 和 TestNG 的 Selenium 项目。
我尝试了几种不同的方法来使用 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 文件中的 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>
最佳答案
看看这个Maven Using TestNG网站。
基本上您所要做的就是向 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
将找不到并运行它们。
您可以通过将这些文件添加到插件配置来更改/添加要包含的文件。
关于maven - 如何使用 Maven POM 文件运行 testNG 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12691570/