参考:
http://blog.csdn.net/langsand/article/details/53764805
http://blog.csdn.net/langsand/article/details/53764805
1.maven 的pom.xml配置:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/velocity/velocity-dep -->
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgs>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation </arg>
<!--<arg>endorseddirs=${endorsed.dir}</arg>-->
</compilerArgs>
</configuration>
</plugin>
<!--添加插件 关联testNg.xml-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<!--这里设置关联的testNG.xml路径,项目根目录下的res文件夹里面-->
<suiteXmlFiles>
<file>res/testNG.xml</file>
</suiteXmlFiles>
<properties>
<!--刚开始这里没有设置默认监听false,所以没有启用reportNG功能。-->
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<!--Setting ReportNG listener-->
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
</build>
2.testNG.xml配置listener
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testproj" parallel="false">
<test name="testDemo1">
<packages>
<package name="com.aika.testng"/>
</packages>
<!--<classes>-->
<!--<class name="com.aika.testng.*"></class>-->
<!--</classes>-->
</test>
<!--<listeners>-->
<!--<listener class-name="org.uncommons.reportng.HTMLReporter" />-->
<!--<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />-->
<!--</listeners>-->
</suite>
上面testNG.xml不设置的话,可以这样设置
3.配置好了,写一个简单的测试用例,此处不多做说明了。
IDEA的终端Terminal窗口,输入:mvn -f pom.xml clean test -DxmlFileName=testNG.xml
testNG.xml对应配置文件名称
生成成功,红框路径打开index.html