常用注解如下:

  • @BeforeSuite: 此注解的方法会在当前测试集合中的任一测试用例前执行
  • @AfterSuite: 此注解的方法会在当前测试集合中的所有测试程序结束后执行
  • @BeforeTest: 此注解的方法在每个Test执行之前会运行
  • @AfterTest: 此注解的方法在每个Test执行之后会运行
  • @BeforeGroups: 此注解的方法在分组测试的任一测试用例执行之前会运行
  • @AfterGroups: 此注解的方法在分组测试的所有测试用例执行之后会运行
  • @BeforeClass: 此注解的方法会在当前测试类中的任一测试用例前执行
  • @AfterClass: 此注解的方法会在当前测试类中的所有测试用例结束后执行
  • @BeforeMethod: 此注解的方法会在当前测试中的每个方法开始之前执行
  • @AfterSuite: 此注解的方法会在当前测试中的每个方法开始之后执行
  • @Test: 表示一个测试用例

注解运用的代码如下:

package cn.gloryroad;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite; public class Annotation {
@Test
public void test1() {
System.out.println("***** test1 被执行 **********");
} @Test
public void test2() {
System.out.println("********* test2 被执行 *********");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("beforeMethod 被执行");
} @AfterMethod
public void afterMethod() {
System.out.println("afterMethod 被执行");
} @BeforeClass
public void beforeClass() {
System.out.println("beforeClass 被执行");
} @AfterClass
public void afterClass() {
System.out.println("afterClass 被执行");
} @BeforeTest
public void beforeTest() {
System.out.println("beforeTest 被执行");
} @AfterTest
public void afterTest() {
System.out.println("afterTest 被执行");
} @BeforeSuite
public void beforeSuite() {
System.out.println("beforeSuite 被执行");
} @AfterSuite
public void afterSuite() {
System.out.println("afterSuite 被执行");
} }

测试结果如下

testng 的常用注解的更多相关文章

  1. TestNG的常用注解

    @BeforeSuite:表示此注解的方法会在当前测试集合(Suite)中的任一测试用例开始运行之前执行 @AfterSuite:表示此注解的方法会在当前测试集合(Suite)中的所有测试程序运行结束 ...

  2. 【转】TestNG常用注解

    http://blog.csdn.net/d6619309/article/details/52435084 TestNG的注解大部分用在方法级别上.常用的注解列举如下: 1. Before类别和Af ...

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

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

  4. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  5. SpringMVC常用注解實例詳解3:@ResponseBody

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  6. SpringMVC常用注解實例詳解2:@ModelAttribute

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  7. Spring常用注解汇总

    本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component- ...

  8. Spring常用注解,自动扫描装配Bean

    1 引入context命名空间(在Spring的配置文件中),配置文件如下: xmlns:context="http://www.springframework.org/schema/con ...

  9. springmvc常用注解与类型转换

    springmvc常用注解与类型转换 一:前置 spring -servlet.xml 注入 <!-- 启用spring mvc 注解 --> <context:annotation ...

随机推荐

  1. Python3元组的简介和遍历

    一.Python3元组简介 1.1.如何创建一个元组 ''' Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号(),列表使用方括号[]. 元组创建很简单,只需要在括号中添 ...

  2. 隐藏和显示div的两种方法

    方式一 style="visibility: none;" visiblity:visible -------->可见 visiblity:hidden -------> ...

  3. 为什么要用urlencode()函数进行url编码

    URLEncode就是将URL中特殊部分进行编码.URLDecoder就是对特殊部分进行解码. 因为当字符串数据以url的形式传递给web服务器时,字符串中是不允许出现空格和特殊字符的 譬如:你要传的 ...

  4. Git远程操作(附重要原理图)

    原文出处: 阮一峰 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容 ...

  5. live2d

    原文来自https://www.fghrsh.net/post/123.html Live2D 看板娘 v1.4 / Demo 3 - 内置 waifu-tips.json (博客园等网站引用推荐) ...

  6. ReentrantLock可重入锁——源码详解

    开始这篇博客之前,博主默认大家都是看过AQS源码的~什么居然没看过猛戳下方 全网最详细的AbstractQueuedSynchronizer(AQS)源码剖析(一)AQS基础 全网最详细的Abstra ...

  7. 五、Uniapp+vue+腾讯IM+腾讯音视频开发仿微信的IM聊天APP,支持各类消息收发,音视频通话,附vue实现源码(已开源)-聊天输入框的实现

    会话好友列表的实现 1.项目引言 2.腾讯云后台配置TXIM 3.配置项目并实现IM登录 4.会话好友列表的实现 5.聊天输入框的实现 6.聊天界面容器的实现 7.聊天消息项的实现 8.聊天输入框扩展 ...

  8. npm ERR! Error: EPERM: operation not permitted

    转载于:https://blog.csdn.net/qq_36772866/article/details/86934950 win10 在npm install时报错 解决方案 删除node-mou ...

  9. ios越狱使用AltDeploy签名

    1.总结 截至目前: 越狱这么多年,用过非自己签名的越狱app, 也用过自己签名的越狱app. A .非自己签名, 别人签名好了越狱app, 下载安装,即可.笔者前期都是用的这样的方式. B.自己编译 ...

  10. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...