三 unitest 测试框架
1 导入包
from appium import webdriver
from time import sleep
import unittest
2 创建全局变量放在类之外
driver=None
3 创建类
3.1 创建测试类
class 类名(unittest.TestCase):
3.2 创建初始化和还原环境的函数
- 这些函数需要放在类中
- cls 不能省略
- 所有测试函数运行前运行一次
- driver 需要声明为全局变量
@clasmethod
def setUpClas(cls):
device={}
device['deviceName']='192.168.120.12:55'
device['platformName']='Android'
device['platformVersion']='9'
device['noRest']=True
device['apPackge']='com.android.quicksearchbox'
device['apActivy']='com.android.quicksearchbox.SearchActivy'
device['unicodeKyboard']= True
device['rsetKeyboard']=True
global driver
driver=webdriver.Remote("htp:/localhost:4723/wd/hub",device)
3.3 测试函数
def 函数名(self):
u'测试描述'
global driver
#其他测试代码
- 函数名必须以 tes 开头
- self 不能省略
- u"测试描述" 可以省略,省略时显示函数名
- 多个测试函数按照函数名的 ASCI 顺序执行
3.4 运行测试
if _name_ = "_main_":
unites.main(verbosity=2)
- 上述代码放在模块内,类之外
- 表示当单独运行模块时才会被执行,import 到其他脚本中是不会被执行
- verbosity=2 表示显示每个用例的详细信息,可以省略,但测试结果不详细
- 测试结果
- .:代表测试通过。
- F:代表测试失败,F 代表 failure。
- E:代表测试出错,E 代表 error。。
- s:代表跳过该测试,s 代表 skip。
网友评论