unittest框架初识
程序员文章站
2024-03-24 10:29:28
...
新建3个文件夹,分别是case、function、test
function文件夹中保存待测试的类
from selenium import webdriver
import os
import re
class getsong:
def getsongmessage(url):
# content = re.compile('qq.com\/ (.*)\.m4a\?').findall(url)[0]
content = re.compile('C400(.*)\.m4a').findall(url)[0]
print(content)
geturl = r'https://y.qq.com/n/yqq/song/' + content + r'.html'
print(geturl)
driver = webdriver.Chrome()
driver.get(geturl)
songname = driver.find_element_by_class_name("data__name_txt").text
singername = driver.find_element_by_class_name("data__singer").text
albumname = driver.find_element_by_class_name("js_album").text
driver.quit()
msg = {
'songname': songname,
'singername': singername,
'albumname': albumname
}
print("歌曲名称为:", songname)
print("歌手名称为:", singername)
print("专辑名称为:", albumname)
return msg
# if __name__ == '__main__':
# url =r'http://111.202.98.148/amobile.music.tc.qq.com/C400003OUlho2HcRHC.m4a?guid=1907614314&vkey=AAA53A6F530A4EACF02F4FAEEA284959F3947FBBE7178875A2916DA14AA315E295090FA10DAA6EB728CE4751AF3AA188170F1F3EAD5BF281&uin=1520&fromtag=66'
# print(type(url))
# getsongmessage(url)
case中保存对应的单元测试case
用例一:
import unittest
from function import getMsg
class testgetMsg(unittest.TestCase):
def setUp(self):
print("test start")
def test_getMsg(self):
b = {
'songname': "告白气球",
'singername': "周杰伦",
'albumname': "周杰伦的床边故事"
}
a = getMsg.getsong.getsongmessage(r'http://111.202.98.148/amobile.music.tc.qq.com/C400003OUlho2HcRHC.m4a?guid=1907614314&vkey=AAA53A6F530A4EACF02F4FAEEA284959F3947FBBE7178875A2916DA14AA315E295090FA10DAA6EB728CE4751AF3AA188170F1F3EAD5BF281&uin=1520&fromtag=66')
self.assertEqual(a,b)
def tearDown(self):
print("test end")
用例二:
import unittest
from function import getMsg
class testgetMsg2(unittest.TestCase):
def setUp(self):
print("test start")
def test_getMsg2(self):
b = {
'songname': "卡路里 (Live)",
'singername': "腾格尔",
'albumname': "2019湖南卫视元宵喜乐会"
}
a = getMsg.getsong.getsongmessage(
r'http://111.202.98.148/amobile.music.tc.qq.com/C400002jG4Rv2DeC3O.m4a?guid=1907614314&vkey=AAA53A6F530A4EACF02F4FAEEA284959F3947FBBE7178875A2916DA14AA315E295090FA10DAA6EB728CE4751AF3AA188170F1F3EAD5BF281&uin=1520&fromtag=66')
self.assertEqual(a, b)
def tearDown(self):
print("test end")
test则用于启动测试
import unittest
from case import testgetMsg
from case import testgetMsg2
#构造测试集
gogogo = unittest.TestSuite()
gogogo.addTest(testgetMsg.testgetMsg("test_getMsg"))
gogogo.addTest(testgetMsg2.testgetMsg2("test_getMsg2"))
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(gogogo)
上一篇: Android--Animation动画介绍和实现
下一篇: 软件架构知识归纳
推荐阅读
-
解决Spring定时计划任务重复执行两次(实例被构造两次)问题的方法 博客分类: JavaSpring spring框架
-
SpringMVC+mybatis+DWR3注解 博客分类: 框架整合Spring springMVC注解SpringMVC+mybatis+DWR3SpringMVC+DWR3注解配置框架整合
-
SpringMVC_3.x_入门指南_4 博客分类: SpringMVC SpringMVC连接Hibernate框架整合
-
unittest框架初识
-
flex的pureMVC+Fabrication的使用例子--HelloWorld 博客分类: Flex FlexFlashGoogle框架Web
-
Spring+SpringMVC+Hibernate整合(封装CRUD操作) 博客分类: 框架整合 SpringSpringMVCHibernate框架整合CRUD
-
ExtJS框架学习笔记 博客分类: ExtJS框架 ExtJS笔记
-
Appium+Python+pytest自动化测试框架
-
框架模式MVP在安卓中的实践
-
框架模式 MVC 在Android中的使用