Read more
Get to grips with Python Python is a hugely popular, open source programming language, especially in the world of web development, and is used by some of the largest and most popular web services including Spotify, YouTube, Google, and the Raspberry Pi.
List of contents
Introduction 1
CHAPTER 1 A History of Testing 5
You Do Test, Don't You? 7
Fundamentals and Best Practices 7
Python Installation 8
Linux 8
Mac 8
Windows 8
Pip 9
Virtualenv 9
Source Control (SVN, Git) 10
Interactive Development Environment (IDE) 11
Summary 12
CHAPTER 2 Writing Unit Tests 15
What Is Unit Testing? 15
What Should You Test? 17
Writing Your First Unit Test 17
Checking Values with the assertEquals Method 18
Checking Exception Handling with assertRaises 20
Following the PEP-8 Standard 22
Unit Test Structure 23
Additional Unit Test Examples 24
Getting Clever with assertRaises 24
Making Your Life Easier with setUp 25
Useful Methods in Unit Testing 27
assertEqual(x, y, msg=None) 27
assertAlmostEqual(x, y, places=None, msg=None, delta=None) 27
assertRaises(exception, method, arguments, msg=None) 28
assertDictContainsSubset(expected, actual, msg=None) 28
assertDictEqual(d1, d2, msg=None) 28
assertTrue(expr, msg=None) 28
assertFalse(expr, msg=None) 29
assertGreater(a, b, msg=None) 29
assertGreaterEqual(a, b, msg=None) 29
assertIn(member, container, msg=None) 30
assertIs(expr1, expr2) 30
assertIsInstance(obj, class, msg=None) 30
assertNotIsInstance(obj, class, msg=None) 30
assertIsNone(obj, msg=None) 30
assertIsNot(expr1, expr2, msg=None) 31
assertIsNotNone(obj, msg=None) 31
assertLess(a, b, msg=None) 31
assertLessEqual(a, b, msg=None) 31
assertItemsEqual(a, b, msg=None) 31
assertRaises(excClass, callableObj, *args, **kwargs, msg=None) 32
Summary 32
CHAPTER 3 Utilizing Unit Test Tools 33
Using Python's Nose 33
Installing Nose 34
Using Nose's Best Features 35
Running Specifi c Test Files 35
Getting More Detail with Verbose 35
Debugging Support with PDB 36
Checking Your Coverage 38
Coloring your tests with Rednose 39
PyTest: An Alternative Test Runner 40
Installing PyTest 40
PyTest's Best Features 41
Running Specifi c Tests 41
Viewing Detail with Verbose and Summary 42
Debugging with PDB 43
Checking Your Coverage with PyTest 45
Choosing Between Nose and PyTest 46
Mock and Patch Tricky Situations 46
Installing the Mock Library 47
Mocking a Class and Method Response 47
When Mock Won't Do, Patch! 50
The Requests Library 50
Patch in Action 50
Advanced Mocking 52
Summary 53
CHAPTER 4 Writing Testable Documentation 55
Writing Your First Doctest 56
Th e Python Shell 56
Adding Doctests to a Method 57
Running Your Doctests 58
Handling Error Cases 59
Advanced Doctest Usage 61
Improving Doctests with Nose Integration 62
Summary 65
Resources 65
CHAPTER 5 Driving Your Development with Tests 67
Agile Development 67
Adopting the Agile Process Now 68
Ethos of Test Driven Development 70
Advantages of Test Driven Development 72
Ping-Pong Programming 72
Test Driving Your Problem 73
Writing Your Failing Test 74
Making Your Test Pass 75
Driving More Features with Tests 75
Wrapping Up the
About the author
David Sale is currently a software developer for British Sky Broadcasting (BSkyB), where he works predominantly with Python and Java. He quickly began making his presence known in the Python Community, having written web articles on various Python topics. David has also given talks on Behaviour Driven Development and Agile Development at the EuroPython conference. He writes about technology for Nettuts+ and Tech.Pro.
Summary
Fundamental testing methodologies applied to the popular Python language Testing Python; Applying Unit Testing, TDD, BDD and Acceptance Testing is the most comprehensive book available on testing for one of the top software programming languages in the world.