三、TestNG的基本注解(1)
Before类别和After类别注解

举例说明
创建两个TestNGAnnotationTest.java和TestNGAnnotationTest2.java的类
TestNGAnnotationTest.java
package com.lc.testngTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class TestNGAnnotationTest { @BeforeSuite
public void beforeSuite() { System.out.println(this.getClass().getName() + " beforeSuite"); } @AfterSuite
public void afterSuite() { System.out.println(this.getClass().getName() + " afterSuite"); } @BeforeTest
public void beforeTest() { System.out.println(this.getClass().getName() + " beforeTest"); } @AfterTest
public void afterTest() { System.out.println(this.getClass().getName() + " afterTest"); } @BeforeClass
public void beforeClass() { System.out.println(this.getClass().getName() + " beforeClass"); } @AfterClass
public void afterClass() { System.out.println(this.getClass().getName() + " afterClass"); } @BeforeMethod
public void beofreMethod() { System.out.println(this.getClass().getName() + " beforeMethod"); } @AfterMethod
public void afterMethod() { System.out.println(this.getClass().getName() + " afterMethod"); } @Test
public void test1() { System.out.println(this.getClass().getName() + " test1"); } @Test
public void test2() { System.out.println(this.getClass().getName() + " test2"); } }
TestNGAnnotationTest2.java
package com.lc.testngTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class TestNGAnnotationTest2 { @BeforeSuite
public void beforeSuite() { System.out.println(this.getClass().getName() + " beforeSuite"); } @AfterSuite
public void afterSuite() { System.out.println(this.getClass().getName() + " afterSuite"); } @BeforeTest
public void beforeTest() { System.out.println(this.getClass().getName() + " beforeTest"); } @AfterTest
public void afterTest() { System.out.println(this.getClass().getName() + " afterTest"); } @BeforeClass
public void beforeClass() { System.out.println(this.getClass().getName() + " beforeClass"); } @AfterClass
public void afterClass() { System.out.println(this.getClass().getName() + " afterClass"); } @BeforeMethod
public void beofreMethod() { System.out.println(this.getClass().getName() + " beforeMethod"); } @AfterMethod
public void afterMethod() { System.out.println(this.getClass().getName() + " afterMethod"); } @Test
public void test1() { System.out.println(this.getClass().getName() + " test1"); } @Test
public void test2() { System.out.println(this.getClass().getName() + " test2"); } }
创建运行项目的xml文件
testng2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="suite1" verbose="1" >
<test name="test1">
<classes>
<class name="com.lc.testngTest.TestNGAnnotationTest"></class>
<class name="com.lc.testngTest.TestNGAnnotationTest2"></class>
</classes>
</test> </suite>
运行结果
[TestNG] Running:
D:\workspace\webTestNG\WebContent\testng2.xml com.lc.testngTest.TestNGAnnotationTest beforeSuite
com.lc.testngTest.TestNGAnnotationTest2 beforeSuite
com.lc.testngTest.TestNGAnnotationTest beforeTest
com.lc.testngTest.TestNGAnnotationTest2 beforeTest
com.lc.testngTest.TestNGAnnotationTest beforeClass
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test1
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test2
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest afterClass
com.lc.testngTest.TestNGAnnotationTest2 beforeClass
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test1
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test2
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 afterClass
com.lc.testngTest.TestNGAnnotationTest afterTest
com.lc.testngTest.TestNGAnnotationTest2 afterTest
com.lc.testngTest.TestNGAnnotationTest afterSuite
com.lc.testngTest.TestNGAnnotationTest2 afterSuite ===============================================
suite1
Total tests run: 4, Failures: 0, Skips: 0
===============================================
其中beforeSuite,afterSuite和beforeTest,afterTest区分不明显,下面修改xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="suite1" verbose="1" >
<test name="test1">
<classes>
<class name="com
[TestNG] Running:
D:\workspace\webTestNG\WebContent\testng.xml com.lc.testngTest.TestNGAnnotationTest beforeSuite
com.lc.testngTest.TestNGAnnotationTest2 beforeSuite
com.lc.testngTest.TestNGAnnotationTest beforeTest
com.lc.testngTest.TestNGAnnotationTest beforeClass
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test1
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest beforeMethod
com.lc.testngTest.TestNGAnnotationTest test2
com.lc.testngTest.TestNGAnnotationTest afterMethod
com.lc.testngTest.TestNGAnnotationTest afterClass
com.lc.testngTest.TestNGAnnotationTest afterTest
com.lc.testngTest.TestNGAnnotationTest2 beforeTest
com.lc.testngTest.TestNGAnnotationTest2 beforeClass
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test1
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 beforeMethod
com.lc.testngTest.TestNGAnnotationTest2 test2
com.lc.testngTest.TestNGAnnotationTest2 afterMethod
com.lc.testngTest.TestNGAnnotationTest2 afterClass
com.lc.testngTest.TestNGAnnotationTest2 afterTest
com.lc.testngTest.TestNGAnnotationTest afterSuite
com.lc.testngTest.TestNGAnnotationTest2 afterSuite ===============================================
suite1
Total tests run: 4, Failures: 0, Skips: 0
===============================================
.lc.testngTest.TestNGAnnotationTest"></class>
</classes>
</test> <test name="test2">
<classes>
<class name="com.lc.testngTest.TestNGAnnotationTest2"></class>
</classes>
</test>
</suite>
运行结果
三、TestNG的基本注解(1)的更多相关文章
- TestNG学习-002-annotaton 注解概述及其执行顺序
此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试 ...
- asp.net mvc3 数据验证(三)—自定义数据注解
原文:asp.net mvc3 数据验证(三)-自定义数据注解 前两节讲的都是asp.net mvc3预先设定的数据注解,但是系统自由的数据注解肯定不适合所有的场合,所以有时候我们需要 ...
- DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之Spr ...
- Spring Boot入门(三):使用Scheduled注解实现定时任务
在程序开发的过程中,经常会使用定时任务来实现一些功能,比如: 系统依赖于外部系统的非核心数据,可以定时同步 系统内部一些非核心数据的统计计算,可以定时计算 系统内部的一些接口,需要间隔几分钟或者几秒执 ...
- Android AOP之路三 Android上的注解
一.简单介绍 啥是注解.不懂的能够先看我上一篇文章. 在android 里面 注解主要用来干这么几件事: 和编译器一起给你一些提示警告信息. 配合一些ide 能够更加方便快捷 安全有效的编写java代 ...
- testng 的常用注解
常用注解如下: @BeforeSuite: 此注解的方法会在当前测试集合中的任一测试用例前执行 @AfterSuite: 此注解的方法会在当前测试集合中的所有测试程序结束后执行 @BeforeTest ...
- TestNG的常用注解
@BeforeSuite:表示此注解的方法会在当前测试集合(Suite)中的任一测试用例开始运行之前执行 @AfterSuite:表示此注解的方法会在当前测试集合(Suite)中的所有测试程序运行结束 ...
- spring boot: Bean的初始化和销毁 (一般注入说明(三) AnnotationConfigApplicationContext容器 JSR250注解)
import org.springframework.context.annotation.AnnotationConfigApplicationContext; 使用AnnotationConfig ...
- 关于整合spring+mybatis 第三种方式-使用注解
使用注解 1.与前两种方法一致.不过稍许不同的是beans.xml中配置的差异. <!-- 配置sqlSessionFactory --> <bean id="sqlSes ...
随机推荐
- Serilog 源码解析——数据的保存(下)
上一篇中,我们提到了日志数据是如何进行解析了.然而,Serilog 灵活采用了不同的策略(Policy)决定一个日志对象如何解析到LogEventPropertyValue的子类对象中,即采用了ISc ...
- LeetCode 中等题解(1)
16 最接近的三数之和 Question 给定一个包括 n 个整数的数组 nums 和 一个目标值 target.找出 nums 中的三个整数,使得它们的和与 target 最接近.返回这三个数的和. ...
- Tomcat口令暴力猜解&&后台getshell
Tomcat环境搭建 windows系统xampp搭建tomcat linux yum搭建tomcat 修改tomcat目录下的conf/tomcat-users.xml文件开启管理后台口令认证 &l ...
- FL Studio里一起安装的ASIO4ALL有什么用?
在我们安装FL Studio时,正常情况下我们安装FL Studio时最多也就改改安装目录,其他的安装设置一般不会动,但看到FL安装的那些东西我们难道不会感到好奇吗?FL Studio安装包括FL S ...
- jmeter测试udp
jemter本身不支持udp测试,需要下载安装第三方插件,或者下载一个插件管理器(下面那个蝴蝶一样的图标),里面有各种插件可以供你下载 下载链接:https://jmeter-plugins.org/ ...
- 多态,向上转型,向下转型,final关键字
多态 概述 多态封装性,继承性之后,面向对象的第三大特性. 定义 多态:是指同一种行为,具有多个不同的表现形式. 生活中,比如跑的动作,猫,狗,大象跑起来的动作都是不一样的,再比如飞的动作 ...
- miniconda安装及使用
conda环境配置 安装conda [清华源下载地址](https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/) 官网或百度云网盘下载对应版本 ...
- GraphicsLab 之 Atmospheric Scattering (二)
作者:i_dovelemon 日期:2020-11-25 主题:Atmospheric Scattering, Volume Scattering, Rayleigh Scattering, Mie ...
- Leetcode 021 Merge Two Sorted Lists
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...
- Android Studio下的简单网页解析
Android Studio下的简单网页解析 一.导入数据 导入前添加依赖 implementation 'org.jsoup:jsoup:1.11.3' 使用字符串导入 String html = ...