1--Test NG--常见测试和注解
第一:注解
(1)@test
(2)@BeforeMethod,@AfterMethod
(3)@BeforeClass,@AfterClass
(4)@BeforeSuite,@AfterSuite
第二:套件测试
(1) SuiteConfig:公共方法
public class SuiteConfig{
@BeforeSuite
public void beforesuit(){
system.out.println("beforesuit 运行啦");
}
@AfterSuite
public void aftersuit(){
system.out.println("aftersuit 运行啦");
}
}
(2) LoginTest:
public class LoginTest{
@Test
public void logintaobao(){
system.out.println("login taobao");
}
}
(3) PayTest
public class PayTest{
@Test
public void paysuccess(){
system.out.println("zhifubao success");
}
}
(4) resource:Testng.xml(名字随意)
<?xml version="1.0" encoding="UTF-8" ?>
<suite name="test">
<test name ="login">
<classes>
<class name="com.curse.testng.suite.suiteconfig"/>
<class name="com.curse.testng.suite.LoginTest"/>
</classes>
</test>
<test name ="pay">
<classes>
<class name="com.curse.testng.suite.suiteconfig"/>
<class name="com.curse.testng.suite.PayTest"/>
</classes>
</test>
</suite>
右键执行testng.xml,结果如下:
beforesuit 运行啦
login taobao
zhifubao success
aftersuit 运行啦
如果在suiteconfig文件中增加beforetest和aftertest,执行结果为:
beforesuit 运行啦
beforetest
login taobao
aftertest
beforetest
zhifubao success
aftertest
aftersuit 运行啦
第三:忽略测试
@test(enabled=false)
第四:分组测试
(1)group在方法上
public class groupsonMethod{
@test(groups="server")
public void test1(){
system.out.println("test1");
}
@test(groups="server")
public void test2(){
system.out.println("test2");
}
@test(groups="client")
public void test3(){
system.out.println("test3");
}
@beforegroups("server")
public void beforegroupsonserver(){
system.out.println("beforeservergroups");
}
@aftergroups("server")
public void aftergroupsonserver(){
system.out.println("afterservergroups");
}
}
运行结果:
beforeservergroups
test1
test2
afterservergroups
test3
(2)groups在类上
@test(groups="stu")
public class groupsonclass1{
}
testng.xml:
<test name="onlyrunstu">
<groups>
<run>
<include name="stu"/>
</run>
</groups>
</test>
第五:异常测试
第六:依赖测试
public class DpendTest{
@test
public void test1(){
system.out.println("test1");
throw new RuntimeException();//打印要写在异常前面,因为抛出异常后,后边的代码都不执行
}
@test(dependsOnMethods={"test1"})
public void test2(){
system.out.println("test2");
}
}
结果:test1
test1执行,test2被忽略了,因为test2的依赖测试test1抛出了异常,执行失败了
第七: 超时测试
public class TimeOutTest{
@test(timeout=3000)//单位为ms
public void testsuccess(){
Thread.sleep(millis:2000);
system.out.println("test1");
}
@test(timeout=2000)//单位为ms
public void testfailed(){
Thread.sleep(millis:3000);
system.out.println("test1");
}
}
1--Test NG--常见测试和注解的更多相关文章
- 使用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- 用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- maven解析xml+测试test+注解
条件:maven项目 测试图: 创建maven项目,在maven项目中scr目录下有main.test(没有就创建) 一.解析XML文件方式 在main目录下有java.resources.webap ...
- spring + myBatis 常见错误:注解事务不回滚
最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...
- web端常见测试
一.登录注册功能 1.页面调转 2.tab键与enter键 3.密码加密显示,是否支持复制粘贴 4.账号密码校验 5.刷新页面,更新验证码 二.界面测试 1.样式.颜色.整体布局风格 2.最大化.最小 ...
- mac使用brew安装配置常见测试工具
Homebrew 包管理工具可以让你安装和更新程序变得更方便,目前在 OS X 系统中最受欢迎的包管理工具是 Homebrew. 安装 在安装 Homebrew 之前,需要将 Xcode Comman ...
- Spring整合JUnit4测试使用注解引入多个配置文件
转自:https://kanpiaoxue.iteye.com/blog/2151903 我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个.我们在类的注释上面会这 ...
- java 日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
- Java日志脱敏框架 sensitive-v0.0.4 系统内置常见注解,支持自定义注解
项目介绍 日志脱敏是常见的安全需求.普通的基于工具类方法的方式,对代码的入侵性太强.编写起来又特别麻烦. 本项目提供基于注解的方式,并且内置了常见的脱敏方式,便于开发. 特性 基于注解的日志脱敏. 可 ...
随机推荐
- 【MIT-6.824】Lab 1: MapReduce
Lab 1链接:https://pdos.csail.mit.edu/6.824/labs/lab-1.html Part I: Map/Reduce input and output Part I需 ...
- centos升级openssl方法及步骤
1.下载要升级到的openssl包https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz 2.升级opens ...
- Linux开发工具_yum使用
yum 的说明与使用 1.什么是yum? 软件包管理器 提供了查找.安装.删除某一个.一组甚至全部软件的命令 命令简洁好用 2.yum语法 yum [ 选项 ] [命令] [安装包] 选项: -h h ...
- 压测过程中出现ops断崖式下跌原因及排解
压测机器: 100台docker redis集群:16个分片 在开始压测的半个小时中,一直很稳定,ops稳定在20w左右.但是接下来突然ops断崖式下跌,ops降到了3w以下.然后持续一段时间,直至变 ...
- srping的历史与哲学
历史: 要谈Spring的历史,就要先谈J2EE.J2EE应用程序的广泛实现是在1999年和2000年开始的,它的出现带来了诸如事务管理之类的核心中间层概念的标准化,但是在实践中并没有获得绝对的成功, ...
- 生成git,ssh的key
git clone ssh 代码: 报错: Warning: Permanently added 'gitee.com,120.55.226.24' (ECDSA) to the list of kn ...
- c语言五子棋
#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <conio.h> ...
- 二、 编写一个类,用两个栈实现队列,支持队列的基本操作(add,poll,peek)
请指教交流! package com.it.hxs.c01; import java.util.Stack; /* 编写一个类,用两个栈实现队列,支持队列的基本操作(add,poll,peek) */ ...
- python修炼第三天
今天主要讲了文件操作,函数与装饰器,装饰器比较烧脑,需要多做练习,逐步分解来进行理解! 加油! 一 文件操作 操作系统 提供文件的概念可以操作磁盘. 文件的只读模式: 注意如果是windows ...
- windows环境下python编码问题
log.info(unicode(str"你好" + "aaa")) 或 Log.info(u"你好111111111111111111111111& ...