java文件

package selniumhomework;

import org.testng.annotations.Test;

public class Test1 {
@Test(groups = {"regression"})
public void method1() {
System.out.println("Method 1 printed");
}
@Test(groups = {"regression"})
public void method2() {
System.out.println("Method 2 printed");
}
@Test(groups = {"smoke"})
public void method3() {
System.out.println("Method 3 printed");
}
@Test(groups = {"regression"})
public void method4() {
System.out.println("Method 4 printed");
}
@Test(groups = {"smoke"})
public void method5() {
System.out.println("Method 5 printed");
}
}

case1:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
<run>
<include name = "regression"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1">
<methods>
   <include name = "method1"/>
   <include name = "method2"/>
   <include name = "method3"/>
   <include name = "method4"/>
   <include name = "method5"/>
</methods>
</class>
</classes>
</test>
</suite>

结果: 当class 包含有methods时,无论method是否被标注为regression,都会被执行。所以5个方法都被打印。当method少了 include method1 时 则不会打印method1(即使它被标注为regression的groups)。所以结论是:

当 class 包含有 methods时,则运行 method include 的方法,不会运行 分组(groups,包括 inlcude和 exclude 都不会运行)里的方法。

----------------------------------------------------------------------------------------------------------------------

case2:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
<run>
<include name = "regression"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1" />
</classes>
</test>
</suite>

结果: 该配置打印那些被标注为 groups=“regression” 的方法。

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

多增加一个java文件:

package selniumhomework;

import org.testng.annotations.Test;

public class Test2 {
@Test(groups = {"smoke"})
public void method1() {
System.out.println("F2: method1");
} @Test(groups = {"regression"})
public void method2() {
System.out.println("F2: method2 ");
} @Test(groups = {"regression", "smoke"}) //注意别写成:groups={"regression,smoke"}
public void method3() {
System.out.println("F2: method3");
} @Test(groups = {"smoke"})
public void method4() {
System.out.println("F2: method4");
}
}

-----------------------------------------------------------------------------------

case1

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
<run>
<include name = "regression"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1" />
<class name="selniumhomework.Test2" />
</classes>
</test>
</suite>

结果: 打印两个java文件中所有被标注为 groups={"regression"}的方法:

Method 1 printed

Method 2 printed

Method 4 printed

F2: method2

F2: method3

-----------------------------------------------------------------------------------

case2

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
<run>
<exclude name = "regression"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1" />
<class name="selniumhomework.Test2" />
</classes>
</test>
</suite>

结果: 打印两个java文件中所有被标注为 groups={"regression"}除外的其他方法 (exclude :不运行的方法):

Method 3 printed

Method 5 printed

F2: method1

F2: method4

-----------------------------------------------------------------------------------

case3

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
<run>
<exclude name = "regression"/>
<include name = "smoke"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1" />
<class name="selniumhomework.Test2" />
</classes>
</test>
</suite>

结果:当某个方法既属于include的组,又属于exclude的组,那么exclude的组优先。所以该配置打印两个java文件中:

1). 排除所有被regression的分组;

2). 属于smoke的分组; 如果一个方法既属于regression的分组又属于smoke的分组,则不打印,如Test2的 method3就没有打印出来。

Method 3 printed

Method 5 printed

F2: method1

F2: method4

-------------------------------------------------------------------------------------

case4

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<groups>
  <define name = "chrome">
<include name = "regression"/>
<include name = "smoke"/>
</define>
<define name = "firefox">
<include name = "regression"/>
</define>
<run>
<include name = "chrome"/>
</run>
</groups>
<classes>
<class name="selniumhomework.Test1"/>
<class name="selniumhomework.Test2"/>
</classes>
</test>
</suite>

这里自定义了两个组,分别针对chrome 和 firefox 的测试策略。chrome分组包含了regression和smoke两组分组;firefox分组则只包含了regression的分组。这样形成了分组包含分组,在设计分组的层次关系时,定义新组能够带来灵活性:可以在代码中使用粒度非常小的分组,然后在运行时刻将这些小分组合并成大分组。这里既可以运行chrome的分组或firefox的分组,还可以运行regression或smoke 的分组,灵活性很高。

Method 1 printed

Method 2 printed

Method 3 printed

Method 4 printed

Method 5 printed

F2: method1

F2: method2

F2: method3

F2: method4

-------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

Note:

1). 可以配置两个.xml文件来驱动case的运行,譬如test1.xml 运行 regression 的cases; test2.xml 运行 smoke 的cases.

而Automatin team 也正是这样做的:在src/test/resources 下的一个文件CISute 中包含两个xml文件,coreRegressionTest.xml

和smokeTest.xml.

2). You can define groups at the class
level and then add groups at the method level:

@Test(groups = { "smoke" })

public class All {

   @Test(groups = { "regression" )

    public void method1() { ... }

    public void method2() { ... }

}

In this class, method2() is part of the group "smoke", which is defined at the class level, while method1() belongs to both "smoke" and "regression".

TestNG 练习的更多相关文章

  1. TestNG 入门教程

    原文出处:http://www.cnblogs.com/TankXiao/p/3888070.html 阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装T ...

  2. JUnit 4 与 TestNG 对比

    原文出处: 付学良的网志 原文出处2: http://www.importnew.com/16270.html -------------------------------------------- ...

  3. JAVA+Maven+TestNG搭建接口测试框架及实例

    1.配置JDK 见另一篇博客:http://www.cnblogs.com/testlurunxiu/p/5933912.html 2.安装Eclipse以及TestNG Eclipse下载地址:ht ...

  4. Idea+TestNg配置test-output输出

    说明:testNG的工程我是使用eclipse创建的,直接导入到idea中,运行test时不会生产test-output,只能在idea的控制台中查看运行结果,然后到处报告,经过不懈的百度终于找到怎么 ...

  5. testng 失败自动截图

    testng执行case failed ,testng Listener会捕获执行失败,如果要实现失败自动截图,需要重写Listener的onTestFailure方法 那么首先新建一个Listene ...

  6. 两种方式testng dataprovider结合csv做测试驱动

    方式一: 第一.读取csv数据源码 import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream ...

  7. java分享第十九天(TestNg的IReporter接口的使用)

     IReporter接口是干嘛的?就是让用户自定义报告的,很多人想要自定义报告,于是乎找各种插件,比如什么testng-xslt啊,reportng啊,各种配置,最后出来的结果,还不能定制化,但为什么 ...

  8. java分享第十八天-02( java结合testng,利用XML做数据源的数据驱动)

    testng的功能很强大,利用@DataProvider可以做数据驱动,数据源文件可以是EXCEL,XML,YAML,甚至可以是TXT文本.在这以XML为例:备注:@DataProvider的返回值类 ...

  9. java分享第十四天(TestNG Assert详解)

     TestNG Assert 详解org.testng.Assert 用来校验接口测试的结果,那么它提供哪些方法呢? 中心为Assert测试类,一级节点为方法例如assertEquals,二级结点为参 ...

  10. TestNG Assert 详解

    org.testng.Assert 用来校验接口测试的结果,那么它提供哪些方法呢? 中心为Assert测试类,一级节点为方法例如assertEquals,二级结点为参数类型及参数个数,double 3 ...

随机推荐

  1. 题解报告:hdu 1421 搬寝室(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9 ...

  2. 463 Island Perimeter 岛屿的周长

    详见:https://leetcode.com/problems/island-perimeter/description/ C++: class Solution { public: int isl ...

  3. 转】Neo4j集群安装实践

    原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/2/ 感谢! Posted: Oct 29, 2013 Ta ...

  4. JAVA一些错误代码

    //算术异常 ArithmeticExecption //空指针异常类 NullPointerException //类型强制转换异常 ClassCastException //数组负下标异常 Neg ...

  5. springmvc系列一 之配置介绍(包含官网doc)

    1.springmvc 官网参考地址: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html 2 ...

  6. Python学习 Day 12 调试 断言 logging pdb pdb.set_trace

    调试 第一种方法简单直接粗暴有效,就是用print把可能有问题的变量打印出来看看: >>> def foo(s): n= int(s) print '>>> n = ...

  7. Linux修改ssh端口,减少暴力破解

    版本centos7   注意:操作时请勿断开当前的ssh连接,以免发生情况登陆不了.   1.修改的是 /etc/ssh/sshd_config 文件 打开文件之后会发现Port是注释掉的,默认为22 ...

  8. 博客之旅 gogogo!

    听说写博客的人都很牛~ 上班一年多了,想记录点什么,so,就写博客吧,整理一些技术点与工作生活心得 欢迎各位道友交流学习 :)

  9. laravel模块 目录设计

  10. mysql.connector.errors.IntegrityError: 1048 (23000): Column 'request_url' cannot be null

    箭头指向的2的方向 少了一个request_url的值 调试: 直接 执行sql语句 是没问题的, 这样就知道问题是出在代码的逻辑 处理了: INSERT INTO response_time (nu ...