Python Unit Test Automation



Download 1,71 Mb.
Pdf ko'rish
bet43/73
Sana31.12.2021
Hajmi1,71 Mb.
#213720
1   ...   39   40   41   42   43   44   45   46   ...   73
Bog'liq
2 5188215245394412341

Listing 4-2.  test_module02.py
from mypackage.mymathlib import *
class TestClass01:
        def test_case01(self):
                print("In test_case01()")
                assert mymathlib().add(2, 5) == 7
Listing 
4-2
 creates a test class called TestClass01. As discussed earlier, you do not 
have to extend it from a parent class. The line containing assert checks if the statement 
mymathlib(). add(2, 5) == 7 is true or false to mark the test method as PASS or FAIL.
Also, create an __init__.py file with the code in Listing 
4-3
 placed in the test 
directory.


Chapter 4 

 nose and nose2
69
Listing 4-3.  __init__.py
all = ["test_module01", "test_module02"]
After this, the chapter04 directory structure will resemble Figure 
4-2
.
The test package is ready now. You can run the tests from the chapter04 directory as 
follows:
nosetests test.test_module02 -v
The output is as follows:
test.test_module02.TestClass01.test_case01 ... ok
----------------------------------------------------------------------
Ran 1 test in 0.008s
OK
The convention for running a specific test class is a bit different in nose. The 
following is the example:
nosetests test.test_module02:TestClass01 -v
You can also run an individual test method as follows:
nosetests test.test_module02:TestClass01.test_case01 -v
Test Discovery
You learned about test discovery in an earlier chapter. nose also supports the test discovery 
process. In fact, test discovery in nose is even simpler than in unittest. You do not have to 
use the discover sub-command for test discovery. You just need to navigate to the project 
directory (chapter04 in this case) and run the nosetests command, as follows:

Download 1,71 Mb.

Do'stlaringiz bilan baham:
1   ...   39   40   41   42   43   44   45   46   ...   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