Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet49/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   45   46   47   48   49   50   51   52   ...   73
Bog'liq
2 5188215245394412341

Listing 4-7.  test_module05.py
from nose.tools import assert_equals
def test_case01():
    print("In test_case01()...")
    assert 2+2 == 5
def test_case02():
    print("In test_case02()...")
    assert_equals(2+2, 5)
Run the code in Listing 
4-7
. The following shows the output:
In setUpPackage()...
test.test_module05.test_case01 ... In test_case01()...
FAIL
test.test_module05.test_case02 ... In test_case02()...
FAIL
In tearDownPackage()...
======================================================================
FAIL: test.test_module05.test_case01
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198,  
in runTest
    self.test(*self.arg)
   File "/home/pi/book/code/chapter04/test/test_module05.py", line 6,  
in test_case01
    assert 2+2 == 5
AssertionError
======================================================================
FAIL: test.test_module05.test_case02
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198,  
in runTest
    self.test(*self.arg)
   File "/home/pi/book/code/chapter04/test/test_module05.py", line 11,  
in test_case02
    assert_equals(2+2, 5)
AssertionError: 4 != 5
----------------------------------------------------------------------
Ran 2 tests in 0.013s
FAILED (failures=2)


Chapter 4 

 nose and nose2
77
Both the test cases failed due to incorrect test inputs. Note the difference between the logs 
printed by these test methods. In test_case02(), you get more information about the 
cause of the failure, as you are using nose’s assert_equals() method.
Testing Tools
nose.tools has a few methods and decorators that come in very handy while you’re 
automating tests.
This section looks at a few of those testing tools.
ok_ and eq_
ok_ and eq_ are shorthand for assert and assert_equals(), respectively. They also come 
with a parameter for an error message when the test case fails. The code in Listing 
4-8
 
demonstrates this.

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   45   46   47   48   49   50   51   52   ...   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