TestNG 在maven2 的pom.xml文件里的配置:
Configuring TestNG
To get started with TestNG, include the following dependency in your project:
[...]
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<scope>test</scope>
<classifier>jdk15</classifier>
</dependency>
[...]
Note:
if you are using JDK 1.4 Javadoc annotations for your TestNG tests, replace jdk15 with jdk14 above.
This is the only step that is required to get started - you can now create tests in your test source directory (eg, src/test/java
, and as long as they are named using the defaults such as *Test.java they will be run by Surefire as TestNG tests.
If you'd like to use a different naming scheme, you can change the includes
parameter, as discussed in the Inclusions and Exclusions of Tests
example.
Using Suite XML Files
Another
alternative is to use TestNG suite XML files. This allows flexible
configuration of the tests to be run. These files are created as
normal, and then added to the Surefire Plugin configuration:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
This configuration will override the includes and excludes patterns and run all tests in the suite files.
Specifying Test Parameters
Your
TestNG test can accept parameters with the @Parameters annotation. You
can also pass parameters from Maven into your TestNG test, by
specifying them as system properties, like this:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<systemProperties>
<property>
<name>browser</name>
<value>firefox</value>
</property>
</systemProperties>
</configuration>
</plugin>
[...]
For more information about setting system properties in Surefire tests, see System Properties
.
Using Groups
TestNG allows you to group your tests. You can then execute a specific group or groups. To do this with Surefire, use the groups
parameter, for example:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<groups>functest,perftest</groups>
</configuration>
</plugin>
[...]
Likewise, the excludedGroups
parameter can be used to run all but a certain set of groups.
Running tests in parallel
TestNG allows you to run your tests in parallel, including JUnit tests. To do this, you must set the parallel
parameter, and may change the threadCount
parameter if the default of 5 is not sufficient. For example:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
[...]
This is particularly useful for slow tests that can have
high concurrency, or to quickly and roughly assess the independance and
thread safety of your tests and code.
Using custom listeners and reporters
TestNG
provides support for attaching custom listeners, reporters, annotation
transformers and method interceptors to your tests. By default, TestNG
attaches a few basic listeners to generate HTML and XML reports.
You can configure multiple custom listeners like this:
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value> <!-- disabling default listeners is optional -->
</property>
<property>
<name>listener</name>
<value>com.mycompany.MyResultListener,com.mycompany.MyAnnotationTransformer,com.mycompany.MyMethodInterceptor</value>
</property>
<property>
<name>reporter</name>
<value>listenReport.Reporter</value>
</property>
</properties>
</configuration>
</plugin>
[...]
分享到:
相关推荐
java+selenium+maven+testng自动化测试框架实例(实际项目)
Selenium2.0+ Maven+TestNG 自动化测试的框架搭建介绍,可执行兼容性测试
基于maven+testng+ExtendReport项目demo,能成功运行,
全网最全Selenium3+Java+Maven+TestNG+ReportNG+SVN+Jenkins自动化测试环境搭建
最近群里经常有人会问到关于maven构建Appium测试项目以及使用testNG生成测试报告的问题,试着搭建了一下,下面是过程: jdk安装过程我这里就不说了 一、下载eclipse,推荐下载Eclipse Luna java EE版本,自带maven...
java+idea+maven+testng环境搭建的步骤(含截图),自动化测试
selenium3+java+Maven+TestNG+ReportNG+Excel自动化参数测试框架源码
eclipsemaven-testng-svn环境配置[整理].pdf
#框架介绍 selenium+java+Maven-TestNG+reportNG+XML • 使用Java作为项目编程语言 • 使用Maven作为项目类型,方便管理架包 • 使用TestNG作为项目运行框架,方便执行测试用例,生成测试报告 • 使用Xml作为...
使用 Jacoco 和 Maven 进行 TestNG 创建文件夹 D:\Embedded_Tomcat_Temp 并将 cgw war 复制到其中。 使用 mvn install 构建战争并将其复制到 D:\Embedded_Tomcat_Temp run mvn "clean package" for testng + ...
基于annotation的测试框架,简单,易用,maven surefire 驱动自动执行测试用例
Java_page_object_maven_testNG Java_page_object_maven_testNG 使用带有页面对象模型的关键字驱动开发的基本项目理解
接口(API)自动化测试
maven testng 报告中文乱码(csdn)————程序
selenide-maven-testng-java
appium自动化教程,主要是为了移动端UI自动化测试,通过
Tatoc_Maven 使用Maven,TestNG的Tatoc自动化代码
使用Java + Maven + TestNG进行页面对象模型设计的Appium移动测试自动化框架。 框架遵循许多行业最佳实践,并在单个代码库中支持Android和iOS。 在“最高评分的Udemy”课程中,分步说明了从头开始构建此框架的过程...