当前位置:网站首页>Unit test framework + Test Suite
Unit test framework + Test Suite
2022-07-03 06:33:00 【Bobo AI leaves work】
Unit test framework
import unittest
class Test_api(unittest.TestCase):
def test_mashang(self):
print('ms3435')
def test_mashang2(self):
print('ms2')
def test_mashang3(self):
print('ms3')
self.assertTrue(True)
test suite
import unittest
from test_api import Test_api
if __name__=='__main__':
suite=unittest.TestSuite()
suite.addTest(Test_api('test_mashang'))
unittest.main(defaultTest='suite')
Test kit transmitter ( Start the py file ):
import unittest
from test_api import Test_api
if __name__=='__main__':
unittest.defaultTestLoader.discover(r'D:\pycharm\PyCharm Community Edition 2021.1.3\jbr\bin\pythonProject\pythonProject37', pattern='test*.py',)
unittest.main()
result
OK
ms3435
ms2
ms3
setUp and tearDown
Ordinary ones don't need decorators , Class methods need decorators @classmethod Otherwise, it will report a mistake
class Test_api(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
print(' front ')
@classmethod
def tearDownClass(cls) -> None :
print(' After after ')
Unconditionally ignore decorators :
@unittest.skip(reason=' Unconditionally ignore ')
def test_mashang2(self):
print('ms2')
True Conditional ignore decorator :
age=16
@unittest.skipIf(age<18,reason=' Age is less than 18, A minor ')
def test_mashang(self):
print('ms3435')
False Conditional ignore decorator :
age=20
@unittest.skipUnless(age<18,reason=' Ignore ')
def test_mashang(self):
print('ms3435')
Assertion judgement
On the current website :
Self.assertin(‘index.php’,driver.current_url)
In source On :
Driver.switch_to frame(' Frame name ')
Self.assertin(‘ sign out ’,driver,page_source)
Driver.switch_to.default_content()
Locate a set of elements
Locate a set of elements :
Driver,fing_elements(By.XPATH,’//IMG[@src=’images/icon_edit.gif’)
Print(len(list))
Click on the first element
List[0].click()
F12 You can pause the browser
The text asserts
text=Driver,fing_elements(By.XPATH,’//IMG[@src=’images/icon_edit.gif’).text
Print(text)
Self.assertequan(text,’ Edit product successfully ’
边栏推荐
- Print time Hahahahahaha
- Oauth2.0 - explanation of simplified mode, password mode and client mode
- The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list
- “我为开源打榜狂”第一周榜单公布,160位开发者上榜
- Request weather interface format, automation
- POI dealing with Excel learning
- Chapter 8. MapReduce production experience
- Naive Bayes in machine learning
- JMeter performance automation test
- 23 design models
猜你喜欢
Project summary --04
2022 cisp-pte (III) command execution
100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
Example of joint use of ros+pytoch (semantic segmentation)
Zhiniu stock project -- 04
ThreadLocal的简单理解
Method of converting GPS coordinates to Baidu map coordinates
Scroll view specifies the starting position of the scrolling element
Selenium - by changing the window size, the width, height and length of different models will be different
Redis cluster creation, capacity expansion and capacity reduction
随机推荐
opencv
数值法求解最优控制问题(一)——梯度法
SQL实现将多行记录合并成一行
How to scan when Canon c3120l is a network shared printer
ruoyi接口权限校验
剖析虚幻渲染体系(16)- 图形驱动的秘密
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
arcgis创建postgre企业级数据库
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
Characteristics and isolation level of database
Yolov3 learning notes
scroll-view指定滚动元素的起始位置
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
Reinstalling the system displays "setup is applying system settings" stationary
Scroll view specifies the starting position of the scrolling element
Pdf files can only print out the first page
Interface test weather API
致即将毕业大学生的一封信
The mechanical hard disk is connected to the computer through USB and cannot be displayed
Simple password lock