TestNG+Maven+IDEA环境搭建

前言:

主要进行TestNG测试环境的搭建 
所需环境: 
1、IDEA UItimate 
2、JDK 
3、Maven

一、创建工程 
File –>new –>Project–>next–>finish

上面两项名称自己定义

最后工程目录 

二、导入相关依赖包和插件

1)添加testng依赖包 
在pom.xml文件添加

   <dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
</dependencies>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2)添加编译插件和执行测试插件

    <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>
<suiteXmlFiles>
<file>res/testNG.xml</file>
</suiteXmlFiles>
<!--<workingDirectory>target/</workingDirectory>-->
</configuration>
</plugin>
</plugins>
</build>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

具体的maven插件请查看

http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin/ 
http://www.infoq.com/cn/news/2011/05/xxb-maven-8-plugin

三、创建测试类 
在新建测试类,代码如下

public class TestDemo
@Test
public void testcase1(){
Assert.assertTrue(false);
System.out.println("testcase1");
}
@Test
public void testcase2(){
Assert.assertTrue(true);
System.out.println("testcase1");
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

IDEA执行编译

编译情况

四、编写testNG.xml

创建一个新的文件夹 res,里面创建testNG.xml (该文件名自己可以定义,相应需要在pom.xml的文件修改对应文件名) 
编写testNG.xml

<?xml version="1.0" encoding="utf-8" ?>
<suite name="testproj" parallel="false">
<test name="testDemo1">
<!--<packages>-->
<!--<package name="com.testproj.Demo"/>-->
<!--</packages>-->
<classes>
<class name="com.testproj.Demo.TestDemo1"></class>
</classes>
</test>
</suite>


差不多搞定了,我们来看下使用maven执行测试

在IDEA控制台Terminal输入

mvn -f pom.xml clean test  -DxmlFileName=testNG.xml

编译结果

测试报告

target/surefire-reports/com.testproj.Demo.TestDemo1文件夹下打开报告 

到此创建TestNG+Maven+IDEA环境完成。

最新文章

  1. C# foreach 中获取索引index的方法
  2. android学习链接
  3. 【重磅推荐】腾讯Bugly2015年移动应用质量大数据报告
  4. Centos6一键搭建L2TP VPN服务器
  5. 2015GitWebRTC编译实录14
  6. 2016 版 Laravel 系列入门教程(二)【最适合中国人的 Laravel 教程】
  7. C++代码重用——包含
  8. js css 构建滚动边框
  9. mac系统在控制台中ping网址提示不能解析host
  10. Asp.net MVC Razor Generator
  11. Yslow-23条规则编辑
  12. ArrayList-VS-LinkedList
  13. [ios2] 开发技巧【转】
  14. 常用统计分析 SQL 在 AWK 中的实现(转)
  15. 支付宝即时到账DEMO配置与使用
  16. S2-032代码执行
  17. Mysql和Hadoop+Hive有什么关系?
  18. MyBatis通过Mapper动态代理来实现curd操作
  19. .NET 使用 Azure Blob 存储图片或文件
  20. JAVA多线程的问题以及处理(一)【转】

热门文章

  1. python 监控redis的进程与端口
  2. jQuery插件--zTree中点击节点实现页面跳转时弹出两个页面的问题
  3. Selenium2+python自动化57-捕获异常(NoSuchElementException)【转载】
  4. 经常用到的Eclipse快捷键(更新中....)
  5. rertful规范
  6. (7)python 函数和lambda表达式
  7. codeforces Round #441 C Classroom Watch【枚举/注意起点】
  8. 最小生成树 (Minimum Spanning Tree,MST) --- Prim算法
  9. ( 转 ) mysql 实战 or、in与union all 的查询效率
  10. bzoj 5347: 冒泡排序