Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet40/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   36   37   38   39   40   41   42   43   ...   73
Bog'liq
2 5188215245394412341

EXERCISE 3-1
unittest
, like all the other python libraries, is too vast a topic to be covered in a 
single book. so, i recommend you complete the following exercises to gain more 
knowledge and experience with 
unittest
.
1.  
Visit the python 3 Documentation page for 
unittest
 at 
https://docs.python.org/3/library/unittest.html
.
2.  
practice all the assertion methods mentioned in this chapter by 
writing tests using each one of them.
3.  
practice using the 
unittest.skipIf(condition, reason)
 
and 
unittest.expectedFailure()
 decorators. Write code to 
demonstrate their functionality.
4.  
Write a test module with multiple test classes and skip an entire 
test class using the 
unittest.skip(reason)
 decorator.
5.  
experiment with raising exceptions in the test fixtures.
Hint: try to run the code in Listing 
3-21
 by enabling each 
commented-out 
raise Exception
 line, one line at a time. this 
will help you understand how an individual fixture behaves 
when you raise an exception in it.
Listing 3-21.  test_module15.py
import unittest
def setUpModule():
#   raise Exception
    pass


Chapter 3 

 Unittest
63
def tearDownModule():
#   raise Exception
    pass
class TestClass15(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
     raise Exception
        pass
    def setUp(self):
#       raise Exception
        pass
    def test_case01(self):
        self.id()
    def tearDown(self):
#       raise Exception
        pass
    @classmethod
    def tearDownClass(cls):
#       raise Exception
        pass
Conclusion
In this chapter, you learned about several important concepts, including test fixtures
test classes, test methods, and test modules. You also learned how to implement all 
these concepts with unittest. Almost all the concepts you learned in this chapter will be 
revisited in later chapters that cover other Python testing frameworks. In the next chapter
we will look at nose and nose2, which are two other popular Python test automation 
frameworks.


65
© Ashwin Pajankar 2017 
A. Pajankar, Python Unit Test Automation, DOI 10.1007/978-1-4842-2677-3_4

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   36   37   38   39   40   41   42   43   ...   73




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish