testNG 注释实例
1. 单个测试用例文件
新建TestDBConnection.java文件
import org.testng.annotations.*; public class TestDBConnection { @Test
public void runOtherTest1() {
System.out.println("@Test - runOtherTest1");
} @Test
public void runOtherTest2() {
System.out.println("@Test - runOtherTest2");
} @Test(groups = "haha")
public void runOtherTest3() {
System.out.println("@Test - runOtherTest3");
} @BeforeClass
public void beforeClass() {
System.out.println("@Test - BeforeClass");
}
@BeforeGroups(groups = "haha")
public void beforeGroups() {
System.out.println("@Test - BeforeGroups");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("@Test - BeforeMethod");
}
@AfterMethod
public void afterMethod() {
System.out.println("@Test - AfterMethod");
}
@AfterGroups(groups = "haha")
public void afterGroups() {
System.out.println("@Test - AfterGroups");
} @AfterClass
public void afterClass() {
System.out.println("@Test - AfterClass");
}
}
配置并运行
点击运行,结果如下:
[TestNG] Running:
/Users/sunmin/Library/Caches/IdeaIC2017.3/temp-testng-customsuite.xml
@Test - BeforeClass
@Test - BeforeMethod
@Test - runOtherTest1
@Test - AfterMethod
@Test - BeforeMethod
@Test - runOtherTest2
@Test - AfterMethod
@Test - BeforeGroups
@Test - BeforeMethod
@Test - runOtherTest3
@Test - AfterMethod
@Test - AfterGroups
@Test - AfterClass ===============================================
Default Suite
Total tests run: 3, Failures: 0, Skips: 0
=============================================== Process finished with exit code 0
2. Test Suit
新建TestDBConfig.java文件,内容如下:
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest; public class TestDBConfig { @BeforeSuite()
public void beforeSuite() {
System.out.println("@BeforeSuite");
} @AfterSuite()
public void afterSuite() {
System.out.println("@AfterSuite");
} @BeforeTest()
public void beforeTest() {
System.out.println("@BeforeTest");
} @AfterTest()
public void afterTest() {
System.out.println("@AfterTest");
} }
新建testng.xml文件,位置放在pom.xml同级,内容如下。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!-- @BeforeSuite -->
<suite name="TestAll"> <!-- @BeforeTest -->
<test name="case1">
<classes>
<class name="TestDBConfig" />
</classes>
</test>
<!-- @AfterTest --> <!-- @BeforeTest -->
<test name="case2">
<classes>
<class name="TestDBConnection" />
</classes>
</test>
<!-- @AfterTest -->
</suite>
<!-- @AfterSuite -->
配置及运行
Test kind需选择Suite,Suite的配置文件选择我们自己的testng.xml文件。点击运行,结果如下:为啥@AfterTest会出现在这个地方?
[TestNG] Running:
/Users/sunmin/Downloads/TestHelloWorld/testng.xml
@BeforeSuite
@BeforeTest
@AfterTest
@Test - BeforeClass
@Test - BeforeMethod
@Test - runOtherTest1
@Test - AfterMethod
@Test - BeforeMethod
@Test - runOtherTest2
@Test - AfterMethod
@Test - BeforeGroups
@Test - BeforeMethod
@Test - runOtherTest3
@Test - AfterMethod
@Test - AfterGroups
@Test - AfterClass
@AfterSuite ===============================================
TestAll
Total tests run: 3, Failures: 0, Skips: 0
=============================================== Process finished with exit code 0
testNG 注释实例的更多相关文章
- 利用Testng注释实现多线程并发测试
Testng 是一款非常优秀的测试框架,真正从测试角度出发,为测试所想.在测试过程中我们经常会遇到对某一个场景做并发请求,主要想了解该程序在并发时是否会有异常或者没考虑到的其他情况,这时往往不是要做性 ...
- C#枚举注释实例
public enum 枚举名称 { /// <summary> /// 注释描述1 /// </summary> ...
- TestNG注释@BeforeGroups与@AfterGroups不执行的处理
在学习TestNG框架注解时发现在执行以下的代码 package com.groups; import org.testng.annotations.AfterGroups; import org.t ...
- selenium TestNG基本注释和属性
TestNG注释详解 suite 属性说明: @name: suite 的名称,必须参数@junit:是否以Junit 模式运行,可选值(true | false),默认"false&quo ...
- Hibernate每个子类一张表(使用注释)实例
在每个子类一张表的情况下,表是根据持久类创建的,但是它们使用主键和外键来重新定义. 所以关系中不会有重复的列. 我们需要在子类中的使用@PrimaryKeyJoinColumn注释和在父类指定@Inh ...
- Selenium和TestNG
本文档由Felipe Knorr Kuhn撰写,并根据其博客上发布的一系列文章进行改编. 建模您的测试用例 在编写测试用例之前,您需要知道如何验证以及将要验证的内容.让我们使用WordPress “创 ...
- Java自动化测试框架-09 - TestNG之依赖注入篇 (详细教程)
1.-依赖注入 TestNG支持两种不同类型的依赖项注入:本机(由TestNG本身执行)和外部(由诸如Guice的依赖项注入框架执行). 1.1-本机依赖项注入 TestNG允许您在方法中声明其他参数 ...
- go语言注释
Go语言注释实例代码教程 - Go支持C语言风格的/* */块注释,也支持C++风格的//行注释. 当然,行注释更通用,块注释主要用于针对包的详细说明或者屏蔽大块的代码. 每个包都应有一个包注解,即 ...
- PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
文档注释,无非“//”和“/**/”两种 ,自己写代码,就那么点,适当写几句就好了:但是一个人总有融入团队的一天,团队的交流不是那几句注释和一张嘴能解决的,还需要通用的注释标准. PHPDoc是PHP ...
随机推荐
- pandas.DataFrame.sample随机抽样
https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&shareId=400000000398 ...
- Java读取CSV数据并写入txt文件
读取CSV数据并写入txt文件 package com.vfsd; import java.io.BufferedWriter; import java.io.File; import java.io ...
- git解决error: The following untracked working tree files would be overwritten by checkout
在IDEA中进行分支切换时,出现如此错误,导致无法正常切换:error: The following untracked working tree files would be overwritten ...
- linux编译Qt+mysql驱动+可执行文件移植目标机
前言: 如果希望自己的Qt/C++程序在目标机上运行,最简单的方法就是在目标机上安装一个Qtcreater[Qtxxx.run],然后编译release的可执行文件,直接拉起即可. 但是有些环境情况比 ...
- ElasticSearch集群状态查看命令大全(转)
原文地址: https://blog.csdn.net/pilihaotian/article/details/52460747 Elasticsearch中信息很多,同时ES也有很多信息查看命令,可 ...
- (原)ffmpeg中的writing_filter翻译
本文的主要目的是梳理,记录自己在学习开发ffmpeg视频滤镜的笔记.参考的主要内容是根据ffmpeg中doc下的writing_filter.txt文件以及ffmpeg的源码. author:liha ...
- tomcat 启动和关闭脚本
start.sh #!/bin/sh . ~/.bash_profile echo "" > ${TOMCAT_HOME}/logs/catalina.out; sh ${T ...
- EasyNVR网页摄像机无插件H5、谷歌Chrome直播方案之使用ffmpeg保存快照数据方法与代码
背景分析 EasyNVR主要功能模块有设备发现与接入.实时直播.摄像机控制.录像与管理.设备快照与状态维护.第三方平台对接,其中设备快照与状态维护主要包括定时检测通道设备的在线状态.定时对通道摄像机进 ...
- 阿里云composer 镜像
2019年12月2日13:54:32 https://developer.aliyun.com/composer 阿里云的镜像更新时间比较及时 本镜像与 Packagist 官方实时同步,推荐使用最新 ...
- jstree:重新加载数据集,刷新树
true:表示获得一个已经存在的jstree实例 $('#tree').jstree(true).destroy();// 清除树节点 // 重新设置树的JSON数据集 $('#tree').jstr ...