中文名: Python Testing Cookbook (第1版)原名: Python Testing Cookbook, 1st edition作者: Greg L. Turnquist资源格式: PDF版本: 英文文字版/更新源代码出版社: Packt Publishing书号: 978-1-84951-466-8发行时间: 2011年05月地区: 美国语言: 英文简介: 内容介绍:This cookbook is written as a collection of code recipes containing step-by-step directionPython Testing CookbookCopyright C 2011 Packt PublishingAll rights reserved. No part of this book may be reproduced stored in a retrieval system, ortransmitted in any form or by any means without the prior written permission ot the publisherexcept in the case of brief quotations embedded in critical articles or reviewsEvery effort has been made in the preparation of this book to ensure the accuracy of theinformation presented. However, the information contained in this book is sold withoutwarranty, either express or implied. Neither the author, nor Packt Publishing, and its dealersand distributors will be held liable for any damages caused or alleged to be caused directly orindirectly by this book.Packt Publishing has endeavored to provide trademark information about all of the companiesand products mentioned in this book by the appropriate use of capitals. However, PacktPublishing cannot guarantee the accuracy of this information.First published: May 2011Production reference: 1100511Published by Packt Publishing Ltd32 Lincoln roadOltonBirmingham, B27 6PA, UKSBN978-1-849514-668www.packtpub.comCover Image by Asher Wishkerman(a. wishkermanampic deCreditsAuthorProject Coordinatorreg L turnquistSrimayee ghoshalReviewersProofreaderMatthew clossonBernadette WatkinsChetan giridharIndexerSylvain HellegouarchHemangini BariMaurice HT LingAcquisition EditiAdline swetha jesuthasTarun SinghCover workDevelopment editorAdline swetha jesuthasHyacintha D'SeTechnical EditorsPallavi KachareSheetDeshpandeditorLaxmi subramanianAbout the AuthorGreg L. turnquist has worked in the software industry since 1997. He is an activeparticipant in the open source community, and has contributed patches to several projectsincluding MythTV, Spring Security, MediaWiki, and the TestNG Eclipse plugin. As a test-bittenscript junky, he has al ways sought the right tool for the job. He is a firm believer in agilepractices and automated testing. He has developed distributed systems, LAMP-based setups,and supported mission-critical systems hosted on various platformsAfter graduating from auburn University with a Master's in Computer Engineering, Gregstarted working with Harris Corporation. He worked on many contracts utilizing many typesof technology. In 2006, he created the Spring Python project and went on to write SpringPython 1.1 in 2010. He joined SpringSource, a division of vMware in 2010, as part of theirinternational software development teamI would like to extend my thanks to Sylvain Hellegouarch, Matt Closson, aswell as my editors for taking the time to technically review this book andprovide valuable feedback. I thank my one-year-old daughter for pulling meaway when I needed a break and my one-month-old son for giving me MANYopportunities in the middle of the night to work on this book. I especiallythank my precious wife sara for the support, encouragement, patience, andmost importantly for saying I think we should strike while the iron is hotwhen I was offered this writing opportunityAbout the reviewersMatthew closson is a creative technologist and entrepreneur at heart he is currentlyemployed as a software engineer by philips healthcare. he is passionate about softwaretesting, 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 onthe beachChetan Giridhar has more than five years experience of working in the software servicesdustry, product companies, and research organizations. He has a string background ofC/C++, Java(certified Java professional) and has a good command of Perl, Python scriptinglanguages, using which he has developed useful tools and automation frameworks. Hisarticles on Code Reviews, Software Automation, and Agile methodologies have beenpublished in international magazines including Testing Experience and agileRecord for whichhe has received appreciation from other industry experts on his website-TechnoBeansChetan has also co-authored a book on Design Patterns in Python that is listed at Python'sOfficial Website. He has given lectures on Python Programming to software professionalsand at educational institutes including the Indian Institute of Astrophysics, Bangalore. Chetanholds a B.E. in Electrical Engineering from the University of Mumbai and feels that the world isfull of knowledgeI take this opportunity to thank rahul verma, who has guided and inspiredme, Ashok mallya and Rishi Ranjan, for their encouragement and for theconfidence they have shown in me. Special thanks to my parents Jayant andjyotsana giridhar, and my wife deepti, who have all been a constant supportSylvain Hellegouarch is a senior software engineer with several years experience indevelopment and performance testing in various companies, both in France and in the UnitedKingdom Passionate about open-source software, he has written several Python projectsaround communication protocols such as Http, XmpP, and the atom Publishing Protocol Hebook, published by Packt Publishing in 2007. Sylvain also reviewed Spring Python, published 'ahas been part of the cherry Py team since 2004 and has also authored the Cherrypy essentialsby Packt Publishing in 2010. His current interests are set on the open-data movement and thewave of innovation it brings to public services. When away from his computer, Sylvain plays theguitar and the drums or spends his time with friends and familyMaurice HT Ling completed his Ph D in Bioinformatics and B Sc(Hons) in Molecular andCell Biology from The University of Melbourne where he worked on microarray analysis andtext mining for protein-protein interactions. He is currently a Senior Scientist (Bioinformatics)in Life Technologies and an Honorary Fellow in The University of melbourne, AustraliaMaurice holds several Chief Editorships including The Python Papers, computational andMathematical Biology, and methods and Cases in Computational, Mathematical, andStatistical Biology. In Singapore, he co-founded the Python User Group Singapore)and hasbeen the co-chair of Py Con Asia-Pacific since 2010. In his free time, Maurice likes to train inthe gym, read, and enjoy a good cup of coffee. He is also a Senior Fellow of the InternationalFitnessAssociationUsa.Hispersonalwebsiteis:http://maurice.vodien.comwww.packtpubcomSupport files, eBookS, discount offers and moreYoumightwanttovisitwww.Packtpub.comforsupportfilesanddownloadsrelatedtoyourbookDid you know that Packt offers eBook versions of every book published, with PdF and ePubtilesavailableYoucanupgradetotheebooKversionatwww.Packtpub.comandasaprintbook customer, you are entitled to a discount on the eBook copy. Get in touch with us atservice@packtpub com for more detailsAtwww.Packtpub.comyoucanalsoreadacollectionoffreetechnicalarticlessignupfora range of free newsletters and receive exclusive discounts and offers on packt books ande BooksPACKTLIBhttp://packtlib.Packtpub.comDo you need instant solutions to your iT questions? PacktLib is Packt's online digital booklibrary. Here, you can access, read and search across Packt's entire library of booksWhy Subscribe?Fully searchable across every book published by packtCopy and paste, print and bookmark contentk on demand and accessible via web browserFree Access for packt account holdersIfyouhaveanaccountwithPacktatwww.PacktPubcom,youcanusethistoaccessPacktLib today and view nine entirely free books. Simply use your login credentials formmediate accessTable of contentsPrefaceChapter 1: Using Unittest To Develop Basic TestsIntroductionAsserting the basics557Setting up and tearing down a test harness11Running test cases from the command line with increased verbosity14Running a subset of test case methods16Chaining together a suite of tests18Defining test suites inside the test module21Retooling old test code to run inside unittest25Breaking down obscure tests into simple ones29Testing the edges35Testing corner cases by iteration39Chapter 2: Running Automated Test Suites with Nose45Introduction45Getting nosy with testing46Embedding nose inside Python49Writing a nose extension to pick tests based on regular expressions52Writing a nose extension to generate a csv report59Writing a project-level script that lets you run different test suites66Chapter 3: Creating Testable Documentation with doctest77ntroduction77Documentingthe basics78Catching stack traces82Running doctests from the command line85Coding a test harness for doctest88Filtering out test noise92