DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
>>> area_of_circle(-1)
Traceback (most recent call last):
File "<pyshell>", line 1, in <module>
File
"/Users/chrijack/Documents/ccnadevnet/areacircle.py",
line 5, in area_of_circle
raise ValueError('Negative radius value
error')
ValueError: Negative radius value error

If you rerun the unit test, you see that it now passes the
new check because an error is raised:


Click here to view code image


..
--------------------------------------------------
-----------------
Ran 2 tests in 0.000s

OK

This simple example barely scratches the surface of how
you can use unit testing to check your software, but it
does show you how a unit test is constructed and, more
importantly, what it does to help you construct resilient
code. Many more tests can be conducted; see the
documentation at
https://docs.python.org/3/library/unittest.html.


EXAM PREPARATION TASKS


As mentioned in the section “How to Use This Book” in
the Introduction, you have a couple of choices for exam
preparation: the exercises here, Chapter 19, "Final
Preparation," and the exam simulation questions on the
companion website.

Free download pdf