在日常开发测试过程中,肯定少不了测试数据的支撑。
模拟测试数据的工具有很多,例如:Mockaroo、DataGenerator、还有之前介绍过的Faker都可以帮助我们快速生成随机的数据,比如:姓名、地址、邮箱、手机号、日期、时间、数字、布尔值等。
但是,这些工具只能帮助我们生成一些基础数据,有时候我们需要的不仅仅是这些基础数据,例如:随机生成一句名人名言、随机生成一句古诗文、获取历史上今天发生的事情、获取今日要闻等等。对于这些需求,我们又该如何实现呢?自己动手去写,显然不太现实,而且会大大降低工作效率。因此,我们可以通过调用一些开放的接口来获取这些数据。
本篇就来分享几个有趣并且免费的开放接口,开箱即用。
接口
随机古诗
Request URL:https://api.apiopen.top/api/sentences
Request Method:GET
Function:随机生成一句古诗文,包含标题及作者。
def demo1(self):"""古诗文@return: 例如:情人怨遥夜,竟夕起相思。——张九龄《望月怀远》"""res = self.requests_http({'method': 'get','url': 'https://api.apiopen.top/api/sentences'}).json()sentences = res['result']['name'] + '——' + res['result']['from']return sentences
随机图片
Request URL:https://api.apiopen.top/api/getImages
Request Method:GET
Function:随机生成图片链接,可指定类型。
def demo2(self):"""获取图片@return:"""res = self.requests_http({'method': 'get','url': 'https://api.apiopen.top/api/getImages','params': {'page': 1,'size': 1,# type可选参数# animal/beauty/car/comic/food/game/movie/person/phone/scenery# 动物/美女/汽车/漫画/食物/游戏/电影/人物/手机/风景'type': ''}}).json()return res
随机一言
Request URL:https://api.oick.cn/yiyan/api.php
Request Method:GET
Function:随机输出一句话。
def demo3(self):"""一言随机输出一句话(鸡汤)@return: 正因为有天空,所以云才能自由的地漂浮。"""res = self.requests_http({'method': 'get','url': 'https://api.oick.cn/yiyan/api.php'}).json()return res
社会语录
Request URL:https://api.oick.cn/yulu/api.php
Request Method:GET
Function:随机生成一句社会经典语录。
def demo4(self):"""社会经典语录@return: 花花世界迷人眼,没有能力别赛脸!"""res = self.requests_http({'method': 'get','url': 'https://api.oick.cn/yulu/api.php'}).json()return res
舔狗日记
Request URL:https://api.oick.cn/dog/api.php
Request Method:GET
Function:随机生成舔狗日记。
def demo5(self):"""舔狗日记@return: 今天一大早就去帮她海底捞排队,她男朋友想吃海底捞,我要是去晚了的话排不上队,她男朋友吃不上海底捞的话又该骂她,我怕她扛不住,她男朋友骂人很凶的."""res = self.requests_http({'method': 'get','url': 'https://api.oick.cn/dog/api.php'}).json()return res
有毒鸡汤
Request URL:https://api.oick.cn/dutang/api.php
Request Method:GET
Function:随机生成一句毒鸡汤。
def demo6(self):"""毒鸡汤@return: 世界上本没有路,走的人多了,老师就开始点名了。"""res = self.requests_http({'method': 'get','url': 'https://api.oick.cn/dutang/api.php'}).json()return res
历史今日
Request URL:https://api.oick.cn/lishi/api.php
Request Method:GET
Function:获取历史上今天发生的事情。
def demo7(self):"""历史上的今天@return:"""res = self.requests_http({'method': 'get','url': 'https://api.oick.cn/lishi/api.php'}).json()for i in res['result']:print(i['date'] + ' ' + i['title'])
励志摸鱼
Request URL:http://bjb.yunwj.top/php/mo-yu/php.php
Request Method:GET
Function:输出摸鱼的躺平语。
def demo8(self):"""励志摸鱼@return:"""res = self.requests_http({'method': 'get','url': 'http://bjb.yunwj.top/php/mo-yu/php.php'}).json()return res
平台
零七生活API
网址:https://api.oick.cn
瓶芯API
网址:http://bjb.yunwj.top/php/api/html.html?7
聚合数据
网址:https://www.juhe.cn/apiservice
以上,完。
脚踏实地,仰望星空,和小编一起学习软件测试,升职加薪!
最后作为一位过来人也是希望大家少走一些弯路,在这里我给大家分享一些软件测试的学习资料和我花了3个月整理的软件测试自学全栈,这些资料希望能给你前进的路上带来帮助。
视频文档获取方式:
这份文档和视频资料,对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!以上均可以分享,点下方小卡片即可自行领取。