Packt Publishing Python Testing Cookbook (2011).pdf
(
30789 KB
)
Pobierz
About the Author
Greg L. Turnquist
has worked in the software industry since 1997. He is an active
participant in the open source community, and has contributed patches to several projects
including MythTV, Spring Security, MediaWiki, and the TestNG Eclipse plugin. As a test-bitten
script junky, he has always sought the right tool for the job. He is a irm believer in agile
practices and automated testing. He has developed distributed systems, LAMP-based setups,
and supported mission-critical systems hosted on various platforms.
After graduating from Auburn University with a Master's in Computer Engineering, Greg
started working with Harris Corporation. He worked on many contracts utilizing many types
of technology. In 2006, he created the Spring Python project and went on to write Spring
Python 1.1 in 2010. He joined SpringSource, a division of VMware in 2010, as part of their
international software development team.
I would like to extend my thanks to Sylvain Hellegouarch, Matt Closson, as
well as my editors, for taking the time to technically review this book and
provide valuable feedback. I thank my one-year-old daughter for pulling me
away when I needed a break and my one-month-old son for giving me MANY
opportunities in the middle of the night to work on this book. I especially
thank my precious wife Sara for the support, encouragement, patience, and
most importantly for saying "I think we should strike while the iron is hot"
when I was offered this writing opportunity.
About the Reviewers
Matthew Closson
is a creative technologist and entrepreneur at heart. He is currently
employed as a software engineer by Philips Healthcare. He is passionate about software
testing, systems integration, and web technologies. When not obsessing over Ruby and C#
code, this elusive developer is likely to be found reading at the local bookstore or relaxing on
the beach.
Chetan Giridhar
has more than ive years experience of working in the software services
industry, product companies, and research organizations. He has a string background of
C/C++, Java (certiied Java professional) and has a good command of Perl, Python scripting
languages, using which he has developed useful tools and automation frameworks. His
articles on Code Reviews, Software Automation, and Agile methodologies have been
published in international magazines including TestingExperience and AgileRecord for which
he has received appreciation from other industry experts on his website—TechnoBeans.
Chetan has also co-authored a book on
Design Patterns in Python
that is listed at Python's
Oficial Website. He has given lectures on Python Programming to software professionals
and at educational institutes including the Indian Institute of Astrophysics, Bangalore. Chetan
holds a B.E. in Electrical Engineering from the University of Mumbai and feels that the world is
full of knowledge.
I take this opportunity to thank Rahul Verma, who has guided and inspired
me, Ashok Mallya and Rishi Ranjan, for their encouragement and for the
conidence they have shown in me. Special thanks to my parents Jayant and
Jyotsana Giridhar, and my wife Deepti, who have all been a constant support.
Table of Contents
Preface
1
Chapter 1: Using Unittest To Develop Basic Tests
5
Introduction
5
Asserting the basics
7
Setting up and tearing down a test harness
11
Running test cases from the command line with increased verbosity
14
Running a subset of test case methods
16
Chaining together a suite of tests
18
Deining test suites inside the test module
21
Retooling old test code to run inside unittest
25
Breaking down obscure tests into simple ones
29
Testing the edges
35
Testing corner cases by iteration
39
Chapter 2: Running Automated Test Suites with Nose
45
Introduction
45
Getting nosy with testing
46
Embedding nose inside Python
49
Writing a nose extension to pick tests based on regular expressions
52
Writing a nose extension to generate a CSV report
59
Writing a project-level script that lets you run different test suites
66
Chapter 3: Creating Testable Documentation with doctest
77
Introduction
77
Documenting the basics
78
Catching stack traces
82
Running doctests from the command line
85
Coding a test harness for doctest
88
Filtering out test noise
92
Table of Contents
Printing out all your documentation including a status report
96
Testing the edges
101
Testing corner cases by iteration
104
Getting nosy with doctest
107
Updating the project-level script to run this chapter's doctests
110
Chapter 4: Testing Customer Stories with Behavior
Driven Development 117
Introduction 117
Naming tests that sound like sentences and stories 120
Testing separate doctest documents 126
Writing a testable story with doctest 130
Writing a testable novel with doctest 136
Writing a testable story with Voidspace 142
Mock and nose 142
Writing a testable story with mockito and nose 147
Writing a testable story with Lettuce 150
Using Should DSL to write succinct assertions with Lettuce 158
Updating the project-level script to run this chapter's BDD tests 163
Chapter 5: High Level Customer Scenarios with Acceptance Testing 169
Introduction 170
Installing Pyccuracy 172
Testing the basics with Pyccuracy 176
Using Pyccuracy to verify web app security 179
Installing the Robot Framework 183
Creating a data-driven test suite with Robot 186
Writing a testable story with Robot 191
Tagging Robot tests and running a subset 197
Testing web basics with Robot 204
Using Robot to verify web app security 208
Creating a project-level script to verify this chapter's acceptance tests 212
Chapter 6: Integrating Automated Tests with Continuous Integration 217
Introduction 217
Generating a continuous integration report for Jenkins using NoseXUnit 220
Coniguring Jenkins to run Python tests upon commit
222
Coniguring Jenkins to run Python tests when scheduled
227
Generating a CI report for TeamCity using teamcity-nose
231
Coniguring TeamCity to run Python tests upon commit
234
Coniguring TeamCity to run Python tests when scheduled
237
ii
Plik z chomika:
krupix.one
Inne pliki z tego folderu:
Addison-Wesley Starting Out with Python (2009).pdf
(34645 KB)
Addison-Wesley Python Programming with the Java Class Libraries, A Tutorial for Building Web and Enterprise Applications with Jython (2002).pdf
(16434 KB)
MIT Press Introduction to Computation and Programming Using Python (2013) (no OCR).pdf
(87897 KB)
AddedBytes Cheat Sheets Python.pdf
(388 KB)
Addison-Wesley Python Essential Reference 4th (2009).pdf
(2491 KB)
Inne foldery tego chomika:
Android Application Development Video Guide Poradnik
Apple iOS 5 and 6 Development eBooks Collection [PDF]
ASP.NET eBooks Collection [PDF]
books
Complete IT Books Pack
Zgłoś jeśli
naruszono regulamin