Unnitest测试框架总结
Unnitest总结
第一点,setUp和tearDown方法
l 每次执行test开头的用例都会执行setUp和tearDown方法
l 如:
import unittest class Mydemo(unittest.TestCase):
def setUp(self):
print('调用setUp方法')
self.a = 1
def test1(self):
print("i am test1 the value of a is {}".format(self.a))
def test2(self):
print("i am test2 the value of a is {}".format(self.a))
def test3(self):
print("i am test3 the value of a is {}".format(self.a))
def tearDown(self):
print("调用tearDown方法")
if __name__ == '__main__':
unittest.main()
n 结果:
第二点: setUpClass和tearDownClass方法
l 如:
import unittest
class Mydemo(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("调用setUpClass\n")
def test1(self):
print("i am test1")
def test2(self):
print("i am test2")
@classmethod
def tearDownClass(cls):
print("调用tearDownClass")
if __name__ == '__main__':
unittest.main()
l 结果:
第三点:定义全局的属性,可以放到setUpClass中testCase中均可去调用
l 如:
class NavigationTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.implicitly_wait(30)
cls.driver.maximize_window()
cls.driver.get('https://www.baidu.com/')
driver = cls.driver #定义在全局中
cls.search_field = driver.find_element_by_name('wd') #定义在全局中 def testBrowserNavigation(self):
self.search_field.clear()
print('执行test1') self.search_field.send_keys('圣女果')
self.search_field.submit()
time.sleep(1) self.assertEqual('圣女果_百度搜索',self.driver.title) self.driver.back()
self.assertTrue(WebDriverWait(self.driver,30).until(expected_conditions.title_contains('百度一下')))
def testBrowserNavigation2(self):
driver = self.driver
search_field = driver.find_element_by_name('wd')
search_field.clear()
print('执行test2') search_field.send_keys('璎珞')
search_field.submit()
time.sleep(1)
@classmethod
def tearDownClass(cls):
driver = cls.driver
time.sleep(10)
driver.quit() if __name__ == "__main__":
unittest.main()
第四点:testCase之间的执行顺序按照默认是以首字母排序的
l 执行顺序test1,test10,....test18,test2,..........test9
Unnitest总结
第一点,setUp和tearDown方法
l 每次执行test开头的用例都会执行setUp和tearDown方法
l 如:
l import unittest
class Mydemo(unittest.TestCase):
def setUp(self):
print('调用setUp方法')
self.a =
1
def test1(self):
print("i am test1 the value of a is {}".format(self.a))
def test2(self):
print("i am test2 the value of a is {}".format(self.a))
def test3(self):
print("i am test3 the value of a is {}".format(self.a))
def tearDown(self):
print("调用tearDown方法")
if __name__ == '__main__':
unittest.main()
n 结果:
第二点: setUpClass和tearDownClass方法
l 如:
l import unittest
class Mydemo(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("调用setUpClass\n")
def test1(self):
print("i am test1")
def test2(self):
print("i am test2")
@classmethod
def tearDownClass(cls):
print("调用tearDownClass")
if __name__ == '__main__':
unittest.main()
l 结果:
n
第三点:定义全局的属性,可以放到setUpClass中testCase中均可去调用
l 如:
l class NavigationTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.implicitly_wait(30)
cls.driver.maximize_window()
cls.driver.get('https://www.baidu.com/')
driver = cls.driver #定义在全局中
cls.search_field = driver.find_element_by_name('wd') #定义在全局中 def testBrowserNavigation(self):
self.search_field.clear()
print('执行test1') self.search_field.send_keys('圣女果')
self.search_field.submit()
time.sleep(1) self.assertEqual('圣女果_百度搜索',self.driver.title) self.driver.back()
self.assertTrue(WebDriverWait(self.driver,30).until(expected_conditions.title_contains('百度一下')))
def testBrowserNavigation2(self):
driver = self.driver
search_field = driver.find_element_by_name('wd')
search_field.clear()
print('执行test2') search_field.send_keys('璎珞')
search_field.submit()
time.sleep(1)
@classmethod
def tearDownClass(cls):
driver = cls.driver
time.sleep(10)
driver.quit() if __name__ == "__main__":
unittest.main()
n
第四点:testCase之间的执行顺序按照默认是以首字母排序的
l 执行顺序test1,test10,....test18,test2,..........test9
Unnitest测试框架总结的更多相关文章
- phpunit 测试框架安装
PHPUnit是一个轻量级的PHP测试框架.它是在PHP5下面对JUnit3系列版本的完整移植,是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计).来自百度百科 一.下载wg ...
- 某互联网后台自动化组合测试框架RF+Sikuli+Python脚本
某互联网后台自动化组合测试框架RF+Sikuli+Python脚本 http://www.jianshu.com/p/b3e204c8651a 字数949 阅读323 评论1 喜欢0 一.**Robo ...
- selenium测试框架使用xml作为对象库
之前已经写过一篇: selenium测试框架篇,页面对象和元素对象的管理 上次使用的excel作为Locator对象管理,由于excel处理不够方便,有以下缺点: 不能实现分page 加载Locato ...
- selenium 测试框架中使用grid
之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...
- selenium测试框架篇,页面对象和元素对象的管理
前期已经做好使用Jenkins做buildhttp://www.cnblogs.com/tobecrazy/p/4529399.html 做自动化框架,不可避免的就是对象库. 有一个好的对象库,可以让 ...
- Junit测试框架 Tips
关于Junit测试框架使用的几点总结: 1.Junit中的测试注解: @Test →每个测试方法前都需要添加该注解,这样才能使你的测试方法交给Junit去执行. @Before →在每个测试方法执行前 ...
- Python几种常用的测试框架
一.测试的常用规则 一个测试单元必须关注一个很小的功能函数,证明它是正确的: 每个测试单元必须是完全独立的,必须能单独运行.这样意味着每一个测试方法必须重新加载数据,执行完毕后做一些清理工作.通常通过 ...
- 测试框架Mocha与断言expect
测试框架Mocha与断言expect在浏览器和Node环境都可以使用除了Mocha以外,类似的测试框架还有Jasmine.Karma.Tape等,也很值得学习. 整个项目源代码: 为什么学习测试代码? ...
- 在测试框架中使用Log4J 2
之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...
随机推荐
- 十九、多文件上传(ajaxFileupload实现多文件上传功能)
来源于https://www.jb51.net/article/128647.htm 打开google 搜索"ajaxFileupload' ‘多文件上传"可以搜到许许多多类似的, ...
- PHP实用代码片段(四)
1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...
- 软件工程(FZU2015) 学生博客列表(最终版)
FZU:福州大学软件工程 张老师的博客:http://www.cnblogs.com/easteast/ 经过前两周选课,最后正式选上课程的所有学生博客如下: 序号 学号后3位 博客 1 629 li ...
- 漫谈数组去重复方法(亮点是ES6的新API)
方法1: 利用遍历的思想来进行. <!DOCTYPE html><html lang="en"><head> <meta charset= ...
- 如何实现用将富文本编辑器内容保存为txt文件并展示
1.实现思路 创建一个xx.txt文件,存放于项目路径下 用文件流去读取文件内容并将读取的内容存放到页面的富文本编辑器框内 富文本编辑框内容改变后,保存时用文件流的方式保存到xx.txt文件中 提示: ...
- PlainElastic.Net
PlainElastic.Net PlainElastic.Net The really plain Elastic Search .Net client. Idea Installation How ...
- PHP Lumen Call to a member function connection() on null 报错
(1/1) Error Call to a member function connection() on nullin Model.php line 1201at Model::resolveCon ...
- windows浏览器访问虚拟机开的rabbitmq服务,无法访问
根据这个博主的建议 https://blog.csdn.net/csdnliuxin123524/article/details/78207427 换了一个浏览器上火狐浏览器输入“localhost: ...
- CentOS6.8 安装配置Mysql
1.下载mysql的repo源 wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2.安装mysql-commun ...
- mysql 常用字段类型
tinyint[(m)] [unsigned] [zerofill] 1字节 极小整数,数据类型用于保存一些范围的整数数值范围: 有符号: -128 - 127. 无符号: - 255 特别的: My ...