testng 的常用注解
常用注解如下:
- @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 的常用注解的更多相关文章
- TestNG的常用注解
@BeforeSuite:表示此注解的方法会在当前测试集合(Suite)中的任一测试用例开始运行之前执行 @AfterSuite:表示此注解的方法会在当前测试集合(Suite)中的所有测试程序运行结束 ...
- 【转】TestNG常用注解
http://blog.csdn.net/d6619309/article/details/52435084 TestNG的注解大部分用在方法级别上.常用的注解列举如下: 1. Before类别和Af ...
- TestNG学习-002-annotaton 注解概述及其执行顺序
此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试 ...
- Spring系列之Spring常用注解总结
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- SpringMVC常用注解實例詳解3:@ResponseBody
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- SpringMVC常用注解實例詳解2:@ModelAttribute
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- Spring常用注解汇总
本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component- ...
- Spring常用注解,自动扫描装配Bean
1 引入context命名空间(在Spring的配置文件中),配置文件如下: xmlns:context="http://www.springframework.org/schema/con ...
- springmvc常用注解与类型转换
springmvc常用注解与类型转换 一:前置 spring -servlet.xml 注入 <!-- 启用spring mvc 注解 --> <context:annotation ...
随机推荐
- [源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC
[源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC 目录 [源码解析] PyTorch 分布式(16) --- 使用异步执行实现批处理 RPC 0x00 摘要 0x0 ...
- 控制 Python 类的序列化过程
问题 有的类是不支持在多进程间传递的,如果非要这么做,可能会引发奇怪的现象.比如下面这段代码: from concurrent.futures import ProcessPoolExecutor, ...
- 打印讲义中的幻灯片编号(O365新功能)
以下听听文档小程序
- WPF控件界面自适应
之前就听说WPF流式布局,顺滑的很.但由于专业只学习了winform,工作对界面的要求并不高一直没去玩它.目前公司一些软件都是WPF布局,加上工作内容涉及Socket通讯较多,决定用WPF做一个通讯小 ...
- SpringBoot整合nacos实现配置中心(配置动态更新)
官方教程:https://nacos.io/zh-cn/docs/quick-start-spring-boot.html Linux使用docker部署nacos:https://www.cnblo ...
- SpringBoot整合openoffice实现word文档的读取和导入及报错处理
先安装openoffice4 Linux系统安装参考:https://www.cnblogs.com/pxblog/p/11622969.html Windows系统安装参考:https://www. ...
- C语言之字符串替换库函数replace
头文件 #include <algorithm> 例子 下面的代码, 将字符串中的 /替换为\ std::string str("C:/demo/log/head/send&qu ...
- 【LeetCode】45. Jump Game II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- 1226 - One Unit Machine
1226 - One Unit Machine PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...
- MCU变量加载过程
前言 在开发mcu代码的时候经常会有些疑惑,变量是怎么在编译之后进入单片机的ram区的呢,特别是在使用keil开发的时候.后来在接触gcc编译器和自研的mcu后,终于明白了这个问题.实际上变量编译后被 ...