国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

自動化測試框架之unittest

這篇具有很好參考價值的文章主要介紹了自動化測試框架之unittest。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1 unittest框架


unittest 是python 的單元測試框架,它主要有以下作用:

提供用例組織與執(zhí)行:當(dāng)你的測試用例只有幾條時,可以不必考慮用例的組織,但是,當(dāng)測試用例達到成百上千條時,大量的測試用例堆砌在一起,就產(chǎn)生了擴展性與維護性等問題,此時需要考慮用例的規(guī)范與組織問題了。單元測試框架就是來解決這個問題的。
提供豐富的比較方法:在用例執(zhí)行完之后都需要將實際結(jié)果與預(yù)期結(jié)果進行比較(斷言),從而斷定用例是否可以順利通過。單元測試一般會提供豐富的斷言方法。例如,判斷相等/不相等、包含/不包含、True/False等斷言方法。
提供豐富的日志:當(dāng)測試用例執(zhí)行失敗時能拋出清晰的失敗原因,當(dāng)所有用例執(zhí)行完成后能提供豐富的執(zhí)行結(jié)果。例如,總的執(zhí)行時間,失敗用例數(shù),成功用例數(shù)等。

unittest里面有四個很重要的概念,test fixture,test case,test suite,test runner。

  • Test Fixture
    對一個測試用例環(huán)境的搭建和銷毀,就是一個fixture,通過覆蓋setUp()和tearDown()方法來實現(xiàn)。
    setUp()方法可以進行測試環(huán)境的搭建,比如獲取待測試瀏覽器的驅(qū)動,或者如果測試中需要訪問數(shù)據(jù)庫,那么可以在setUp()中通過建立數(shù)據(jù)庫連接來進行初始化。
    tearDown()方法進行環(huán)境的銷毀,可以進行關(guān)閉瀏覽器,關(guān)閉數(shù)據(jù)庫連接,清除數(shù)據(jù)庫中產(chǎn)生的數(shù)據(jù)等操作;
  • Test Case
    一個TestCase的實例就是一個測試用例。測試用例就是一個完整的測試流程,包括測試前準(zhǔn)備環(huán)境的搭建(setUp)、實現(xiàn)測試過程的代碼,以及測試后環(huán)境的還原(tearDown)。單元測試(unit test)的本質(zhì)就在這里,一個測試用例就是一個完整的測試單元,可以對某一個功能進行驗證。
  • Test Suite
    一個功能的驗證往往需要多個測試用例,可以把多個測試用例集合在一起執(zhí)行,這個就產(chǎn)生了測試套件TestSuite的概念。Test Suit用來將多個測試用例組裝在一起;
    Test Runner測試的執(zhí)行也是非常重要的一個概念,在unittest框架中,通過TextTestRunner類提供的run()方法來執(zhí)行test suite/test case。
from selenium import webdriver
import unittest
import time
import os
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

class Baidu1(unittest.TestCase):
    def setUp(self):
        print("-----setUp-----")
        self.driver = webdriver.Chrome()
        self.url = "https://www.baidu.com/"
        self.driver.maximize_window()
        time.sleep(3)
    
    def tearDown(self):
        print("-----tearDown-----")
        self.driver.quit()
    
    def test_hao(self):
        print("111111111")
        driver = self.driver
        url = self.url
        driver.get(url)
        driver.find_element(By.LINK_TEXT,"hao123").click()
        time.sleep(6)
    
    def test_hbaidu(self):
        print("22222222")
        driver = self.driver
        url = self.url
        driver.get(url)
        driver.find_element(By.ID,"kw").send_keys("unittest")
        driver.find_element(By.ID,"su").submit()
        time.sleep(5)
        print(driver.title)
        # self.assertNotEqual(driver.title, "百度一下_百度搜索", msg="不相等")
        # self.assertTrue("beautiful"=="beauty", msg="Not Equal!")
        time.sleep(6)
    
    def saveScreenAsPhoto(self, driver, file_name):
        if not os.path.exists("./image"):
            os.makedirs("./image")
        now = time.strftime("%Y%m%d-%H%M%S", time.localtime(time.time()))
        driver.get_screenshot_as_file("./image/" + now + "-" + file_name)
        time.sleep(3)
        print("3333333")

if __name__ == "__main__":
    unittest.main()

這個腳本中的類 Baidu1 繼承了unittest.TestCase類,所以它使用了unittest框架來組織測試用例(TestCase)。
setUp() 和 setDown() 是unittest框架中的測試固件。
以test_開頭命名的方法,是測試方法,在運行整個類的時候會默認執(zhí)行。
unittest提供了全局的main()方法,使用它可以方便地將一個單元測試模塊變成可以直接運行的測試腳
本。main()方法搜索所有包含在該模塊中以”test"命名的測試方法,并自動執(zhí)行他們。

2 批量執(zhí)行腳本


2.1 構(gòu)建測試套件

當(dāng)我們增加了被測試功能和相應(yīng)的測試用例之后,我們就需要把多個測試用例組織在一起執(zhí)行,這就需要用到上文中提到的測試套件Test Suite
假設(shè)我們已經(jīng)編寫了testbaidu1.py,testbaidu2.py兩個文件

testbaidu2.py

from selenium import webdriver
import unittest
import time
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

class Baidu2 (unittest.TestCase) :
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.baidu.com/"
        self.driver.maximize_window()
        self.verificationErrors=[]
        self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
    
    def test_hao(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element(By.LINK_TEXT,"新聞").click()
        time.sleep(6)
        self.assertTrue("123" == "1234", msg="not true")
        time.sleep(3)
    
    def test_baidusearch(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element(By.ID,"kw").clear()
        driver.find_element(By.ID,"kw").send_keys(u"unittest")
        driver.find_element(By.ID,"su").click()
    time.sleep(6)
   
    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e:
            return False
        return True
        
    def is_alert_present(self):
        try:
            self.driver.switch_to.alert
        except NoAlertPresentException as e:
            return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to.alert
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

if __name__ == "__main__":
    unittest.main(verbosity=2)
  • addTest()

TestSuite類的addTest()方法可以把不同的測試類中的測試方法組裝到測試套件中,但是addTest()一次只能把一個類里面的一個測試方法組裝到測試套件中。方式如下:
將testbaidu1.py、testbaidu2.py中的測試方法放到一個測試套件中,在testsuite.py中實現(xiàn)。
testsuite.py

import unittest
from testUnittest import testbaidu1
from testUnittest import testbaidu2

def createsuite():
    #addTest
    suite = unittest.TestSuite()
    suite.addTest(testbaidu1.Baidu1("test_hao"))
    suite.addTest(testbaidu1.Baidu1("test_hbaidu"))
    suite.addTest(testbaidu2.Baidu2("test_hao"))
    suite.addTest(testbaidu2.Baidu2("test_baidusearch"))
    return suite

if __name__=="__main__":
    suite = createsuite()
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

但是上述做法有兩個不方便的地方,阻礙腳本的快速執(zhí)行,必須每次修改testsuite.py:

  1. 需要導(dǎo)入所有的相關(guān)的py文件,比如 import testbaidu1,每新增一個腳本就需要導(dǎo)入一個
  2. addTest一次只能增加一個測試方法,如果一個py文件中有10個測試方式,如果都要組裝到測試套件中,就需要增加10次
  • makeSuite()和TestLoader()的應(yīng)用

在unittest 框架中提供了makeSuite() 的方法,makeSuite可以實現(xiàn)把測試用例類內(nèi)所有的測試case組成的測試套件TestSuite ,unittest 調(diào)用makeSuite的時候,只需要把測試類名稱傳入即可。
TestLoader 用于創(chuàng)建類和模塊的測試套件,一般的情況下,使TestLoader().loadTestsFromTestCase(TestClass) 來加載測試類。
runall.py

import unittest,csv
import os,sys
import time
import testbaidu1
import testbaidu2

#手工添加案例到套件,
def createsuite():
    suite = unittest.TestSuite()
    #將測試用例加入到測試容器(套件)中
    suite.addTest(unittest.makeSuite(testbaidu1.Baidu1))
    suite.addTest(unittest.makeSuite(testbaidu2.Baidu2))
    return suite
'''
suite1 = unittest.TestLoader().loadTestsFromTestCase(testbaidu1.Baidu1)
suite2 = unittest.TestLoader().loadTestsFromTestCase(testbaidu2.Baidu2)
suite = unittest.TestSuite([suite1, suite2])
return suite
'''
if __name__=="__main__":
    suite=createsuite()
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

經(jīng)過makeSuite()和TestLoader()的引入,我們不用一個py文件測試類,只需要導(dǎo)入一次即可。

  • discover()的應(yīng)用

discover 是通過遞歸的方式到其子目錄中從指定的目錄開始, 找到所有測試模塊并返回一個包含它們對象的TestSuite ,然后進行加載與模式匹配唯一的測試文件,discover 參數(shù)分別為discover(dir,pattern,top_level_dir=None)
runall.py—注意路徑

import unittest,csv
import os,sys
import time

#手工添加案例到套件,
def createsuite():
    discover=unittest.defaultTestLoader.discover("../testUnittest",pattern='test*.py',top_level_dir=None)
    print (discover)
    return discover

if __name__=="__main__":
    suite=createsuite()
    runner = unittest.TextTestRunner(verbosity=2)
    runner.run(suite)

2.2 用例的執(zhí)行順序

unittest 框架默認加載測試用例的順序是根據(jù)ASCII 碼的順序,數(shù)字與字母的順序為: 0 ~ 9,A ~ Z,a ~ z
對于測試目錄與測試文件來說, unittest 框架同樣是按照這個規(guī)則來加載測試用例

2.3 忽略用例執(zhí)行

語法:

@unittest.skip(u'The function was canceled, neglects to perform thecase')
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Baidu1(unittest.TestCase):
#test fixture,初始化環(huán)境
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.baidu.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    @unittest.skip("skipping")
    def test_baidusearch(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element(By.ID,"kw").click()
        driver.find_element(By.ID,"kw").clear()
        driver.find_element(By.ID,"kw").send_keys(u"測試")
        driver.find_element(By.ID,"su").click()
        driver.find_element(By.ID,"su").click()
    
    def test_hao(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element(By.LINK_TEXT,"hao123").click()
        self.assertEqual(u"hao123_上網(wǎng)從這里開始", driver.title)

#判斷element是否存在,可刪除
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
#判斷alert是否存在,可刪除
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True

#關(guān)閉alert,可刪除
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

#test fixture,清除環(huán)境
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    #執(zhí)行用例
    unittest.main()

3 unittest斷言

自動化的測試中, 對于每個單獨的case來說,一個case的執(zhí)行結(jié)果中, 必然會有期望結(jié)果與實際結(jié)果, 來判斷該case是通過還是失敗, 在unittest 的庫中提供了大量的實用方法來檢查預(yù)期值與實際值, 來驗證case的結(jié)果, 一般來說, 檢查條件大體分為等價性, 邏輯比較以及其他, 如果給定的斷言通過, 測試會繼續(xù)執(zhí)行到下一行的代碼, 如果斷言失敗, 對應(yīng)的case測試會立即停止或者生成錯誤信息( 一般打印錯誤信息即可) ,但是不要影響其他的case執(zhí)行。

unittest 的單元測試庫提供了標(biāo)準(zhǔn)的xUnit 斷言方法。下面是一些常用的斷言

斷言方法 斷言描述
assertEqual(arg1, arg2, msg=None) 驗證arg1=arg2,不等則fail
assertNotEqual(arg1, arg2, msg=None) 驗證arg1 != arg2, 相等則fail
assertTrue(expr, msg=None) 驗證expr是true,如果為false,則fail
assertFalse(expr,msg=None) 驗證expr是false,如果為true,則fail
assertIs(arg1, arg2, msg=None) 驗證arg1、arg2是同一個對象,不是則fail
assertIsNot(arg1, arg2, msg=None) 驗證arg1、arg2不是同一個對象,是則fail
assertIsNone(expr, msg=None) 驗證expr是None,不是則fail
assertIsNotNone(expr, msg=None) 驗證expr不是None,是則fail
assertIn(arg1, arg2, msg=None) 驗證arg1是arg2的子串,不是則fail
assertNotIn(arg1, arg2, msg=None) 驗證arg1不是arg2的子串,是則fail
assertIsInstance(obj, cls, msg=None) 驗證obj是cls的實例,不是則fail
assertNotIsInstance(obj, cls,msg=None) 驗證obj不是cls的實例,是則fail

4 HTML報告生成

腳本執(zhí)行完畢之后,還需要看到HTML報告,下面我們就通過HTMLTestRunner.py 來生成測試報告。
修改runall.py

import unittest,csv
import os,sys
import time
import HTMLTestRunner

#手工添加案例到套件,
def createsuite():
    discover=unittest.defaultTestLoader.discover('../testUnittest',pattern='test*.py',top_level_dir=None)
    print (discover)
    return discover

if __name__=="__main__":
    curpath=sys.path[0]
    #取當(dāng)前時間
    now=time.strftime("%Y-%m-%d-%H %M %S",time.localtime(time.time()))
    if not os.path.exists(curpath+'/resultreport'):
        os.makedirs(curpath+'/resultreport')
    filename=curpath+'/resultreport/'+now+'resultreport.html'
    with open(filename,'wb') as fp:
    #出html報告
        runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u'測試報告',description=u'用例執(zhí)行情況',verbosity=2)
        suite=createsuite()
        runner.run(suite)

5 異常捕捉與錯誤截圖

用例不可能每一次運行都成功,肯定運行時候有不成功的時候。如果可以捕捉到錯誤,并且把錯誤截圖保存,這將是一個非常棒的功能,也會給我們錯誤定位帶來方便。

例如編寫一個函數(shù),關(guān)鍵語句為driver.get_screenshot_as_file:

def savescreenshot(self,driver,file_name):
if not os.path.exists('./image'):
	os.makedirs('./image')
now=time.strftime("%Y%m%d-%H%M%S",time.localtime(time.time()))
#截圖保存
driver.get_screenshot_as_file('./image/'+now+'-'+file_name)
time.sleep(1)

示例:testscreenshot.py

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
import os

class Baidu1(unittest.TestCase):
    #test fixture,初始化環(huán)境
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.baidu.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    #測試用例,必須以test開頭
    def test_hao(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element(By.LINK_TEXT,"hao123").click()
        time.sleep(2)
        try:
            self.assertEqual(u'hao_上網(wǎng)從這里開始', driver.title)
        except:
            self.savescreenshot(driver,'hao.png')
   
    #判斷element是否存在,可刪除
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    #判斷alert是否存在,可刪除
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    #關(guān)閉alert,可刪除
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    #test fixture,清除環(huán)境
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
    
    def savescreenshot(self,driver,file_name):
        if not os.path.exists('./image'):
            os.makedirs('./image')
            now=time.strftime("%Y%m%d-%H%M%S",time.localtime(time.time()))
            #截圖保存
            driver.get_screenshot_as_file('./image/'+now+'-'+file_name)
            time.sleep(1)

if __name__ == "__main__":
    #執(zhí)行用例
    unittest.main()

'''
可以增加verbosity參數(shù),例如unittest.main(verbosity=2)
在主函數(shù)中,直接調(diào)用main() ,在main中加入verbosity=2 ,這樣測試的結(jié)果就會顯示的更加詳細。
這里的verbosity 是一個選項, 表示測試結(jié)果的信息復(fù)雜度,有三個值:
0 ( 靜默模式): 你只能獲得總的測試用例數(shù)和總的結(jié)果比如總共100個失敗,20 成功80
1 ( 默認模式): 非常類似靜默模式只是在每個成功的用例前面有個“ . ” 每個失敗的用例前面有個“F”
2 ( 詳細模式): 測試結(jié)果會顯示每個測試用例的所有相關(guān)的信息
'''

6 數(shù)據(jù)驅(qū)動

之前我們的case都是數(shù)據(jù)和代碼在一起編寫。考慮如下場景:
需要多次執(zhí)行一個案例,比如baidu搜索,分別輸入中文、英文、數(shù)字等進行搜索,這時候需要編寫3個案例嗎?有沒有版本一次運行?
python 的unittest 沒有自帶數(shù)據(jù)驅(qū)動功能。所以如果使用unittest,同時又想使用數(shù)據(jù)驅(qū)動,那么就可以使用DDT來完成。
ddt的安裝:

pip install ddt
python setup.py install

dd.ddt
裝飾類,也就是繼承自TestCase的類。
ddt.data
裝飾測試方法。參數(shù)是一系列的值。

  1. data(value) 一次性傳入一個參數(shù)
  2. data(value1,value2,…) 一次性傳入多個參數(shù),需要用@unpack映射
  3. data(*解析數(shù)據(jù)的方法(txt/csv文件))
    ddt.file_data
    裝飾測試方法。參數(shù)是文件名。文件可以是json 或者 yaml類型。
    注意,如果文件以”.yml”或者”.yaml”結(jié)尾,ddt會作為yaml類型處理,其他所有文件都會作為json文件處理。
    如果文件中是列表,每個列表的值會作為測試用例參數(shù),同時作為測試用例方法名后綴顯示。
    如果文件中是字典,字典的key會作為測試用例方法的后綴顯示,字典的值會作為測試用例參數(shù)。
    ddt.unpack
    傳遞的是復(fù)雜的數(shù)據(jù)結(jié)構(gòu)時使用。比如使用元組或者列表,添加unpack之后,ddt會自動把元組或者列表對應(yīng)到多個參數(shù)上。字典也可以這樣處理。

Testddt.py:文章來源地址http://www.zghlxwxcb.cn/news/detail-428435.html

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
import os,sys,csv
from ddt import ddt, data, unpack ,file_data

def getCsv(file_name):
    rows=[]
    path=sys.path[0].replace('\testddt','')
    print (path)
    with open(path+'/data/'+file_name,'r+b') as f:
        readers=csv.reader(f,delimiter=',',quotechar='|')
        next(readers,None)
        for row in readers:
            temprows=[]
            for i in row:
                temprows.append(i.decode('gbk'))
            rows.append(temprows)
            return rows

#引入ddt
@ddt
class Testddt(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.baidu.com"
        self.verificationErrors = []
        self.accept_next_alert = True
        
    #測試用例,必須以test開頭
    #增加ddt數(shù)據(jù)
    @data('selenium','unittest','Junit')
    #@data(2,3,4)
    #單變更時不使用unpack
    #@data([3, 2], [4, 3], [5, 3])
    # @data(*getCsv('test_baidu_data.csv'))
    #使用file_data需要在cmd窗口下運行,否則找不到文件
    #@file_data('test_data_list.json')
    # @unpack
    def test_hao(self,value,expected_value):
    # def test_hao(self,value):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element(By.ID,"kw").clear()
        driver.find_element(By.ID,"kw").send_keys(value)
        driver.find_element(By.ID,"su").click()
        time.sleep(2)
        self.assertEqual(expected_value, driver.title)
        print (expected_value)
        print (driver.title)
    
    #判斷element是否存在,可刪除
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    #判斷alert是否存在,可刪除
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    #關(guān)閉alert,可刪除
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    #test fixture,清除環(huán)境
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
    
    def savescreenshot(self,driver,file_name):
        if not os.path.exists('./image'):
            os.makedirs('./image')
        now=time.strftime("%Y%m%d-%H%M%S",time.localtime(time.time()))
        #截圖保存
        driver.get_screenshot_as_file('./image/'+now+'-'+file_name)
        time.sleep(1)

if __name__ == "__main__":
    #執(zhí)行用例
    unittest.main()

到了這里,關(guān)于自動化測試框架之unittest的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Python自動化測試框架:Pytest和Unittest的區(qū)別

    Python自動化測試框架:Pytest和Unittest的區(qū)別

    pytest和unittest是Python中常用的兩種測試框架,它們都可以用來編寫和執(zhí)行測試用例,但兩者在很多方面都有所不同。本文將從不同的角度來論述這些區(qū)別,以幫助大家更好地理解pytest和unittest。 1. 原理 pytest是基于Python的assert語句和Python的自省特性實現(xiàn)測試框架,其原理是基于

    2024年02月10日
    瀏覽(29)
  • 【Python+requests+unittest+excel】實現(xiàn)接口自動化測試框架

    【Python+requests+unittest+excel】實現(xiàn)接口自動化測試框架

    一、框架結(jié)構(gòu): ?工程目錄 二、Case文件設(shè)計 三、基礎(chǔ)包 base 3.1 封裝get/post請求(runmethon.py) 3.2 封裝mock(mock.py) 四、數(shù)據(jù)操作包 operation_data 4.1 獲取excel單元格中的內(nèi)容(get_data.py) ? 4.2?獲取excel中每個列(data_config.py) 4.3?解決數(shù)據(jù)依賴(dependent.py?) 五、工具類包 to

    2024年02月15日
    瀏覽(25)
  • python接口自動化測試 —— unittest框架suite、runner詳細使用

    python接口自動化測試 —— unittest框架suite、runner詳細使用

    測試套件,理解成測試用例集 一系列的測試用例,或測試套件,理解成測試用例的集合和測試套件的集合 當(dāng)運行測試套件時,則運行里面添加的所有測試用例 測試運行器 用于執(zhí)行和輸出結(jié)果的組件 使用測試套件時,測試用例的執(zhí)行順序可以自定義,按照添加的順序執(zhí)行 有

    2024年03月16日
    瀏覽(28)
  • 自動化測試——unittest框架(單元測試)

    自動化測試——unittest框架(單元測試)

    目錄 一、unittest框架解析 1.1unittest的5個重要概念 1.1測試用例的編寫及代碼 1.2斷言 1.3用例的執(zhí)行順序 1.4測試用例綜合管理框架 1.5HTML報告生成 參考博文 unittest 單元測試提供了創(chuàng)建測試用例,測試套件以及批量執(zhí)行的方案, unittest 在安裝pyhton 以后就直接自帶了,直接import

    2024年01月17日
    瀏覽(25)
  • unittest自動化測試框架詳解

    unittest自動化測試框架詳解

    目錄 一、單元測試的定義 二、unittest框架及原理 三、unittest的斷言 四、TestCase測試用例 五、TestFixure測試夾具 六、TestSuite測試套件 七、TestRunner執(zhí)行用例 ? 單元測試是指,對軟件中的最小可測試單元在與程序其他部分相隔離的情況下進行檢查和驗證的工作,這里的最小可測

    2024年02月04日
    瀏覽(24)
  • 自動化測試框架之unittest

    unittest 是python 的單元測試框架,它主要有以下作用: 提供用例組織與執(zhí)行 :當(dāng)你的測試用例只有幾條時,可以不必考慮用例的組織,但是,當(dāng)測試用例達到成百上千條時,大量的測試用例堆砌在一起,就產(chǎn)生了擴展性與維護性等問題,此時需要考慮用例的規(guī)范與組織問題了

    2024年02月01日
    瀏覽(25)
  • (六)Selenium自動化測試實戰(zhàn)—unittest框架

    (六)Selenium自動化測試實戰(zhàn)—unittest框架

    上一篇:(五)Selenium自動化測試實戰(zhàn)—PO模式_要開朗的spookypop的博客-CSDN博客 先看下代碼的運行效果: 運行自動化測試代碼 unittest是python單元測試框架,它提供了一組豐富的工具來構(gòu)建和運行測試,可以滿足日常做自動化測試的需求。 上一篇詳細的介紹了如何用PO模式寫登

    2023年04月14日
    瀏覽(19)
  • 自動化測試框架unittest與pytest的區(qū)別!

    自動化測試框架unittest與pytest的區(qū)別!

    前面文章已經(jīng)介紹了python單元測試框架,大家平時經(jīng)常使用的是unittest,因為它比較基礎(chǔ),并且可以進行二次開發(fā),如果你的開發(fā)水平很高,集成開發(fā)自動化測試平臺也是可以的。而這篇文章主要講unittest與pytest的區(qū)別,pytest相對unittest而言,代碼簡潔,使用便捷靈活,并且插

    2024年02月15日
    瀏覽(27)
  • 自動化測試概念(以及部分框架,selenium,unittest)

    ??能夠代替手工測試的方法和工具都可以稱為自動化測試 ?? ??例如 ??針對不同的測試對象 ??web自動化 ??app自動化 ?接口自動化 ?? ??針對不同的測試類型 ??功能測試自動化 ??鏈接測試自動化 ??性能測試自動化 ??安全測試自動化 ?? ??實施自動化測試的目的在于

    2024年03月14日
    瀏覽(25)
  • Selenium+Unittest自動化測試框架實戰(zhàn)(框架源碼都給你)

    Selenium+Unittest自動化測試框架實戰(zhàn)(框架源碼都給你)

    目錄 前言 項目框架 首先管理時間 !/usr/bin/env python3 -- coding:utf-8 -- 配置文件 conf.py config.ini# 讀取配置文件 記錄操作日志 簡單理解POM模型 管理頁面元素 封裝Selenium基類 創(chuàng)建頁面對象 熟悉unittest測試框架 編寫測試用例 執(zhí)行用例 生成測試報告 執(zhí)行并生成報告 發(fā)送結(jié)果郵件 se

    2024年02月15日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包