常用注解如下:

  • @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. GIT最基本使用

    带'*':必须操作 不带'*':可能需要而且经常用的 常见步骤为下: *1.克隆项目:有两种不同类型的网址(https/ssh) git clone [url] *2.初始化本地仓库 git init ...

  2. CF638A Home Numbers 题解

    Content Vasya 的家在一条大街上,大街上一共有 \(n\) 座房子,其中,奇数编号的房子在大街的一侧,从左往右依次编号为 \(1,3,5,7,...,n-1\),偶数编号的房子在大街的另一 ...

  3. LuoguB2030 计算线段长度 题解

    Content 已知线段的两个端点的坐标 \(A(X_a,Y_a),B(X_b,Y_b)\) ,求线段 \(AB\) 的长度. 数据范围:\(|X_a|,|Y_a|,|X_b|,|Y_b|\leqsl ...

  4. CF111A Petya and Inequiations 题解

    Content 请找出一个由 \(n\) 个正整数组成的数列 \(\{a_1,a_2,\dots,a_n\}\),满足以下两种条件: \(\sum\limits_{i=1}^na_i^2\geqsla ...

  5. PSpice基本仿真分析例程

    一.瞬态分析 二.直流分析 2.1.直流分析电路 2.2.直流分析配置 2.3.直流分析输出波形 受供电电源的限制,输出最大值为±15V. 三.交流分析 3.1.1.交流分析电路1 3.1.1.交流分 ...

  6. 输入npm install 报错npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.13.1 postinstall: `node scripts/build.js`

    输入npm install 报以下错误 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.13.1 postinstall: ...

  7. 【LeetCode】1022. Smallest Integer Divisible by K 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. 从头造轮子:python3 asyncio 之 run(2)

    前言 书接上文,本文造第二个轮子,也是asyncio包里面非常常用的一个函数run 一.知识准备 ● 相对于run_until_complete,改动并不大,就是将入口函数重新封装了一下,基础知识主要 ...

  9. IntelliJ IDEA打war包

    1.按ctrl+alt+shift+s键打开Project Structure,点击+号图标,选择"Artifacts->Web Application Archive" 2 ...

  10. The Expressive Power of Neural Networks: A View from the Width

    目录 概 主要内容 定理1 定理2 定理3 定理4 定理1的证明 Lu Z, Pu H, Wang F, et al. The expressive power of neural networks: ...