zoukankan      html  css  js  c++  java
  • python+requests+HTMLTestRunner接口测试

    1、编写一个完整的接口测试脚本,并生成测试报告,有助于今后的学习,python脚本各式各样找一种最适合自己的。

    import unittest
    import requests
    import HTMLTestRunner
    
    class logintest(unittest.TestCase):
        def setUp(self):
            self.url = "http:www.xxx.com/login.html"
    
        def testlogin(self):
            form = {"username":12456,"password":12345}
            r = requests.post(self.url,data=form)
            self.assertEqual(r.text,"登录成功")
    
        def testlogin2(self):
            form = {"username":"","password":12345}
            r = requests.post(self.url,data=form)
            self.assertEqual(r.text,"用户名不能为空")
    
        def testlogin3(self):
            form = {"username":12456,"password":""}
            r = requests.post(self.url,data=form)
            self.assertEqual(r.text,"密码不能为空")
    
        def testlogin4(self):
            form = {"username": 12456, "password": 9999}
            r = requests.post(self.url, data=form)
            self.assertEqual(r.text, "账号或密码错误")
    
    def suite():
        loginTestCase = unittest.makeSuite(logintest,"test")
        return loginTestCase
    
    
    if __name__ == "__main__":
        fr = open("result.html","wb")
        runner = HTMLTestRunner.HTMLTestRunner(stream=fr,title="测试报告",description="详情")
        runner.run(suite())
    

      

  • 相关阅读:
    SSH服务附带----SFTP
    SSH附带的远程拷贝----SCP
    linux下的SSH服务
    model.form使用,配合form的钩子
    import_module 导入变量的包
    dir函数
    python爬虫之scrapy
    python爬虫之解析库Beautiful Soup
    django 过滤器,标签
    django 验证码实现
  • 原文地址:https://www.cnblogs.com/mtfan01/p/11485016.html
Copyright © 2011-2022 走看看