1. 单类,无继承父子关系

  • code:
 public class basicTest {
@BeforeSuite(alwaysRun = true)
public void beforeSuite_basicTest() throws InterruptedException {
System.out.println("beforeSuite_basicTest");
Thread.sleep(1000);
} @AfterSuite(alwaysRun = true)
public void afterSuite_basicTest() throws InterruptedException {
System.out.println("afterSuite_basicTest");
Thread.sleep(1000);
} @BeforeClass(alwaysRun = true)
public void beforeClass_basicTest() throws InterruptedException {
System.out.println("beforeClass_basicTest");
Thread.sleep(1000);
} @AfterClass(alwaysRun = true)
public void afterClass_basicTest() throws InterruptedException {
System.out.println("afterClass_basicTest");
Thread.sleep(1000);
} @BeforeTest(alwaysRun = true)
public void beforeTest_basicTest() throws InterruptedException {
System.out.println("beforeTest_basicTest");
Thread.sleep(1000);
}
@AfterTest(alwaysRun = true)
public void afterTest_basicTest() throws InterruptedException {
System.out.println("afterTest_basicTest");
Thread.sleep(1000);
} @BeforeMethod(alwaysRun = true)
public void beforeMethod_basicTest() throws InterruptedException {
System.out.println("beforeMethod_basicTest");
Thread.sleep(1000);
}
@AfterMethod(alwaysRun = true)
public void afterMethod_basicTest() throws InterruptedException {
System.out.println("afterMethod_basicTest");
Thread.sleep(1000);
}
@Test
public void test_basicTest1() throws InterruptedException {
System.out.println("test_basicTest1");
Thread.sleep(1000);
} @Test
public void test_basicTest2() throws InterruptedException {
System.out.println("test_basicTest2");
Thread.sleep(1000);
}
}
  • 执行结果:
beforeSuite_basicTest
beforeTest_basicTest
beforeClass_basicTest
beforeMethod_basicTest
test_basicTest1
afterMethod_basicTest
beforeMethod_basicTest
test_basicTest2
afterMethod_basicTest
afterClass_basicTest
afterTest_basicTest
afterSuite_basicTest

2. 2个类,存在继承关系,注解函数不存在同名。

  • code:
public class bizTest extends basicTest{

    @BeforeClass(alwaysRun = true)
public void beforeClass_bizTest() throws InterruptedException {
System.out.println("beforeClass_bizTest");
Thread.sleep(1000);
} @AfterClass(alwaysRun = true)
public void afterClass_bizTest() throws InterruptedException {
System.out.println("afterClass_bizTest");
Thread.sleep(1000);
} @BeforeTest(alwaysRun = true)
public void beforeTest_bizTest() throws InterruptedException {
System.out.println("beforeTest_bizTest");
Thread.sleep(1000);
}
@AfterTest(alwaysRun = true)
public void afterTest_bizTest() throws InterruptedException {
System.out.println("afterTest_bizTest");
Thread.sleep(1000);
}
@Test
public void test_bizTest1() throws InterruptedException {
System.out.println("test_bizTest1");
Thread.sleep(1000);
} @Test
public void test_bizTest2() throws InterruptedException {
System.out.println("test_bizTest2");
Thread.sleep(1000);
}
}
  • 执行结果:

注意:此处因执行内容较多,手动进行分行,方面了解执行顺序。

beforeSuite_basicTest
beforeSuite_bizTest beforeTest_basicTest
beforeTest_bizTest beforeClass_basicTest
beforeClass_bizTest beforeMethod_basicTest
beforeMethod_bizTest test_bizTest1 afterMethod_bizTest
afterMethod_basicTest beforeMethod_basicTest
beforeMethod_bizTest test_bizTest2 afterMethod_bizTest
afterMethod_basicTest afterClass_bizTest
afterClass_basicTest afterTest_bizTest
afterTest_basicTest afterSuite_bizTest
afterSuite_basicTest

3. 总结

注解执行顺序:suite, test,  class, method

父/子类执行顺序:先执行父类,再执行子类。

testng基础知识:注解的执行顺序的更多相关文章

  1. 14、testng.xml 设置用例执行顺序

    目录如下: TestGroup.java 代码如下: package com.testng.cn; import org.testng.annotations.*; import static org ...

  2. Linq基础知识之延迟执行

    Linq中的绝大多数查询运算符都有延迟执行的特性,查询并不是在查询创建的时候执行,而是在遍历的时候执行,也就是在enumerator的MoveNext()方法被调用的时候执行,大说数Linq查询操作实 ...

  3. TestNG学习-002-annotaton 注解概述及其执行顺序

    此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试 ...

  4. C#基础知识之父子类,实例、静态成员变量,构造函数的执行顺序(经典示例)

    父子类.示例.静态成员变量.构造函数的概念的基础理解完全可以利用下面的示例诠释,非常经典,直接上代码: public class ShowInfo { public ShowInfo(string i ...

  5. C++ 顺序容器基础知识总结

    0.前言 本文简单地总结了STL的顺序容器的知识点.文中并不涉及具体的实现技巧,对于细节的东西也没有提及.一来不同的标准库有着不同的实现,二来关于具体实现<STL源码剖析>已经展示得全面细 ...

  6. 夯实Java基础系列7:一文读懂Java 代码块和执行顺序

    目录 Java中的构造方法 构造方法简介 构造方法实例 例 1 例 2 Java中的几种构造方法详解 普通构造方法 默认构造方法 重载构造方法 java子类构造方法调用父类构造方法 Java中的代码块 ...

  7. Java基础系列5:Java代码的执行顺序

    该系列博文会告诉你如何从入门到进阶,一步步地学习Java基础知识,并上手进行实战,接着了解每个Java知识点背后的实现原理,更完整地了解整个Java技术体系,形成自己的知识框架. 一.构造方法 构造方 ...

  8. 使用TestNG框架测试用例执行顺序问题

    既然是讨论执行顺序问题,那么用例肯定是批量执行的,批量执行的方法有mvn test.直接运行testng.xml文件,其中直接运行testng.xml文件的效果与pom文件中配置执行testng.xm ...

  9. 夯实Java基础系列7:Java 代码块和执行顺序

    本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial 喜欢的话麻烦点下 ...

随机推荐

  1. python--生成测试数据

    1.方法 import datetime params_dict_data = { "system_id":"systemId001", "order ...

  2. 2017 Multi-University Training Contest - Team 5——HDU6095&&HDU6090&&HDU

    HDU6095——Rikka with Competition 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6095 题目意思:抱歉虽然是签到题,现场 ...

  3. AJAX Form Submit Framework 原生js post json

    https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest <!doctype ht ...

  4. DEV中gridview常用属性

    1.隐藏最上面的GroupPanel: gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值: sValue=Table.Rows[g ...

  5. Centos locate 文件搜索命令(十一)

    locate命令 locate 文件名 在后台数据库中按文件名搜索,搜索速度更快 /var/lib/mlocate #locate命令所搜索的后台数据库 updatedb 更新数据库 locate搜索 ...

  6. c/c++分割字符串

    c++分割字符串: http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html c分割字符串: http://www.martinb ...

  7. LInux进程虚拟地址空间的管理

    2017-04-07 脱离物理内存的管理,今天咱们来聊聊进程虚拟内存的管理.因为进程直接分配和使用的都是虚拟内存,而物理内存则是有系统“按需”分配给进程,在进程看来,只知道虚拟内存的存在! 前言: 关 ...

  8. 通过virt-manager 利用NFS创建、迁移虚拟机2

    前面一篇文章介绍了利用NFS创建虚拟机的过程,本文就介绍下如何利用NFS对虚拟机进行动态迁移. 动态迁移就是把一台虚拟机在不停止其运行的情况下迁移到另一台物理机上.这看起来似乎不太可能,不过还好kvm ...

  9. hadoop streaming anaconda python 计算平均值

    原始Liunx 的python版本不带numpy ,安装了anaconda 之后,使用hadoop streaming 时无法调用anaconda python  , 后来发现是参数没设置好... 进 ...

  10. 开发者应该了解的API技术清单

    近几年,API经济纷纷崛起,无论是国外还是国内,众多厂商积极开放API.开发者很多时候是要借助这些API,才能轻松构建出一款应用,极大地提高开发效率和开发质量.文中整理了一份API服务清单,内容涵盖: ...