TestNG+Maven+IDEA环境搭建

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环境完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值