25,99 €
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. Python is a natural choice for new and experienced developers, and this hands-on resource is a much needed guide to enterprise-level testing development methodologies. The book will show you why Unit Testing and TDD can lead to cleaner, more flexible programs. Unit Testing and Test-Driven Development (TDD) are increasingly must-have skills for software developers, no matter what language they work in. In enterprise settings, it's critical for developers to ensure they always have working code, and that's what makes testing methodologies so attractive. This book will teach you the most widely used testing strategies and will introduce to you to still others, covering performance testing, continuous testing, and more. * Learn Unit Testing and TDD--important development methodologies that lie at the heart of Agile development * Enhance your ability to work with Python to develop powerful, flexible applications with clean code * Draw on the expertise of author David Sale, a leading UK developer and tech commentator * Get ahead of the crowd by mastering the underappreciated world of Python testing Knowledge of software testing in Python could set you apart from Python developers using outmoded methodologies. Python is a natural fit for TDD and Testing Python is a must-read text for anyone who wants to develop expertise in Python programming.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 286
Veröffentlichungsjahr: 2014
This edition first published 2014
© 2014 David Sale
Registered office
John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom
For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com.
The right of the author to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior permission of the publisher.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United States and/or other countries, and may not be used without written permission. Python is a registered trademark of the Python Software Foundation. All other trademarks are the property of their respective owners. John Wiley & Sons, Ltd. is not associated with any product or vendor mentioned in the book.
A catalogue record for this book is available from the British Library.
ISBN 978-1-118-90122-9 (paperback); ISBN 978-1-118-90124-3 (ePub); 978-1-118-90125-0 (ePDF)
Set in 10/12.5 ChaparralPro-Light by TCS/SPS
Printed in the USA by Bind-Rite
Some of the people who helped bring this book to market include the following:
Editorial and Production
VP Consumer and Technology Publishing Director: Michelle Leete
Associate Director–Book Content Management: Martin Tribe
Associate Publisher: Chris Webb
Executive Commissioning Editor: Craig Smith
Project Editor: Sydney Argenta
Copy Editor: Debbye Butler
Technical Editors: Jeff Yonker, Alex Bradbury, Andrew Robinson, and Harry Percival
Editorial Manager: Rev Mengle
Senior Project Editor: Sara Shlaer
Editorial Assistant: Claire Johnson
Marketing
Marketing Manager: Lorna Mein
Assistant Marketing Manager: Dave Allen
DAVID SALE is a Software Developer currently working at British Sky Broadcasting (BSkyB) in London, UK as of 2014. He obtained a degree in Computing at the University of Leeds. Whilst studying Computing, Python was taught as the main programming language of the course. This is very different to many other University’s where languages such as Java are taught initially.
This is where David’s interest in Python first began and he has looked to further his knowledge in what has become his core programming language.
Following University, David joined BSkyB in September 2011, as part of the Software Engineering Academy graduate scheme. The scheme proved to be an excellent platform for David to launch his career in software development.
Notably, David has worked on a RESTful Python application that models BSkyB’s products and offers, applies complex pricing rules and business logic, whilst delivering a completely data driven approach to the problem. David has also worked on a project using a Hypermedia approach to sharing data across the application stack to deliver an innovative solution delivering sales to existing customers of BSkyB.
David 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, which was held in Florence, Italy in 2012 and 2013 respectively, with videos of the talks available on YouTube.
David follows Agile Development principles whilst working at BSkyB, with pair programming and Test/Behaviour Driven Development a must. From this focus on testing from such an early point in his career, he has picked up many tips and techniques in Python testing which allows development of quality software, which the business has up most confidence in. It is hoped the tips and advice in this book allow you to learn and improve your daily testing skills in Python.
You can find more on David’s current and previous projects at: www.dsale.co.uk.
First and foremost I would like to thank Craig Smith, Executive Commissioning Editor at Wiley for approaching me with the opportunity to write this book and giving me the confidence in my writing to go for this project; Sydney Jones Argenta, Project Editor, for editing the book so diligently and keeping me up to date throughout the project; Jeff Younker, Alex Bradbury, Andrew Robinson, and Harry Percival Technical Editors for ensuring my code was up to the standard expected by the community and the best it could be.
Secondly, I’d like to give my gratitude to my employer British Sky Broadcasting (Sky). I joined Sky through their Software Engineering Academy graduate scheme and have since progressed to a Software Developer. Without their investment in me, I would not have learned some of the skills and advice that I can now share in this book. They also happily granted me permission to work on this book and helped me find the time to deliver the project alongside my work commitments. Please visit http://workforsky.com if you are interested in joining the team or www.skygraduates.com for more on graduate schemes at Sky.
I’d like to thank my partner Katherine Sweeney, for being so patient in supporting me whilst working on this book. Without her love and support, I would never have dreamed to deliver a project like this and she constantly reminds me to believe in myself. This book is an achievement for us together and I am thankful to have her by my side.
Finally, I would like to thank my brothers Stefan and Matthew Sale for always supporting me in my endeavours but in particular my parents, Ronald and Jennifer Sale. From an early age I have always been taught to work hard and reach for your goals. This book is testament to those words and without the drive to achieve that they have passed on to me; I could never have seen such a big project through. This book is for them and all the people who have supported me in my career as a Software Developer.
Table of Contents
Introduction
Chapter 1: A History of Testing
You Do Test, Don’t You?
Fundamentals and Best Practices
Python Installation
Pip
Virtualenv
Source Control (SVN, Git)
Interactive Development Environment (IDE)
Summary
Chapter 2: Writing Unit Tests
What Is Unit Testing?
What Should You Test?
Writing Your First Unit Test
Checking Values with the assertEquals Method
Checking Exception Handling with assertRaises
Following the PEP-8 Standard
Unit Test Structure
Additional Unit Test Examples
Getting Clever with assertRaises
Making Your Life Easier with setUp
Useful Methods in Unit Testing
Summary
Chapter 3: Utilizing Unit Test Tools
Using Python’s Nose
Installing Nose
Using Nose’s Best Features
PyTest: An Alternative Test Runner
Installing PyTest
PyTest’s Best Features
Choosing Between Nose and PyTest
Mock and Patch Tricky Situations
Installing the Mock Library
Mocking a Class and Method Response
When Mock Won’t Do, Patch!
Summary
Chapter 4: Writing Testable Documentation
Writing Your First Doctest
The Python Shell
Adding Doctests to a Method
Running Your Doctests
Handling Error Cases
Advanced Doctest Usage
Improving Doctests with Nose Integration
Summary
Resources
Chapter 5: Driving Your Development with Tests
Agile Development
Adopting the Agile Process Now
Ethos of Test Driven Development
Advantages of Test Driven Development
Ping-Pong Programming
Test Driving Your Problem
Writing Your Failing Test
Making Your Test Pass
Driving More Features with Tests
Wrapping Up the Task
Summary
Resources
Chapter 6: Writing Acceptance Tests
What Is Acceptance Testing?
Anatomy of an Acceptance Test
Using Gherkin Syntax
The Magic Is in the Step File
Goals of Acceptance Testing
Implementing Developer and QA Collaboration
Letting Behavior Drive Your Problem
Writing Your Failing Acceptance Test
Defining Your Steps
Implementing Your Code
Developing More of the Feature
Delivering the Finished Article
Advanced Acceptance Test Techniques
Scenario Outline
Tables of Data in Scenarios
Summary
Resources
Chapter 7: Utilizing Acceptance Test Tools
Cucumber: The Acceptance Test Standard
Lettuce in Detail
Tagging
Fail Fast
Nosetest Integration
Robot: An Alternative Test Framework
Installing Robot
Writing a Test Case
Implementing Keywords
Running Robot Tests
Summary
Resources
Chapter 8: Maximizing Your Code’s Performance
Understanding the Importance of Performance Testing
JMeter and Python
Installation
Configuring Your Test Plans
Utilizing Your Test Plans Effectively
Code Profiling with cProfile
Run a cProfile Session
Analyzing the cProfile Output
Summary
Resources
Chapter 9: Looking After Your Lint
Coming to Grips with Pylint
Installing Pylint
Using Pylint
Understanding the Pylint Report
Customizing Pylint’s Output
Covering All Your Code with Unit Tests
Installing Coverage
Using Coverage
Advanced Coverage Options
Summary
Resources
Chapter 10: Automating Your Processes
Build Paver Tasks
Installing Paver
Creating a Paver Task
Executing Paver Tasks
Defining a Default Build
Setting Up Automated Builds
Installing Jenkins
Adding Coverage and PyLint Reports
Making Your Build Status Highly Visible
Summary
Resources
Chapter 11: Deploying Your Application
Deploying Your Application to Production
Creating a Deployable Artifact
QA Environment
Implementing Stage and Production Environments
Implementing a Cloud Deployment
Smoke Testing a Deployed Application
Example Application Stack
Smoke Test Scenarios
Implementing Smoke Tests
Summary
Resources
Chapter 12: The Future of Testing Python
Stub the Solution
Making Deployment Natural
Automating (Nearly) Everything
Working in Public
Collaborating on Step Definitions
Final Thoughts
Resources
Table of Contents
Begin Reading
1
2
3
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
55
56
57
58
59
60
61
62
63
64
65
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
203
204
205
206
207
208
209
210
IF YOU HAVE picked up this book, you clearly have some interest in the world of Python. Perhaps you have just started to learn the language. Maybe you have some Python experience and are looking to learn more about the world of testing. You also could have many years of Python under your belt and want to refresh your testing skills. Whatever your reasons, you will pick up some new skills.
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!
Lesen Sie weiter in der vollständigen Ausgabe!