Details

Testing Python


Testing Python

Applying Unit Testing, TDD, BDD and Acceptance Testing
1. Aufl.

von: David Sale

25,99 €

Verlag: Wiley
Format: EPUB
Veröffentl.: 03.07.2014
ISBN/EAN: 9781118901243
Sprache: englisch
Anzahl Seiten: 240

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

<b>Fundamental testing methodologies applied to the popular Python language</b> <p><i>Testing Python; Applying Unit Testing, TDD, BDD and Acceptance Testing</i> 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.</p> <p>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.</p> <ul> <li>Learn Unit Testing and TDD—important development methodologies that lie at the heart of Agile development</li> <li>Enhance your ability to work with Python to develop powerful, flexible applications with clean code</li> <li>Draw on the expertise of author David Sale, a leading UK developer and tech commentator</li> <li>Get ahead of the crowd by mastering the underappreciated world of Python testing</li> </ul> <p>Knowledge of software testing in Python could set you apart from Python developers using outmoded methodologies. Python is a natural fit for TDD and <i>Testing Python</i> is a must-read text for anyone who wants to develop expertise in Python programming.</p>
Introduction 1 <p><b>CHAPTER 1 A History of Testing 5</b></p> <p>You Do Test, Don’t You? 7</p> <p>Fundamentals and Best Practices 7</p> <p>Python Installation 8</p> <p>Linux 8</p> <p>Mac 8</p> <p>Windows 8</p> <p>Pip 9</p> <p>Virtualenv 9</p> <p>Source Control (SVN, Git) 10</p> <p>Interactive Development Environment (IDE) 11</p> <p>Summary 12</p> <p><b>CHAPTER 2 Writing Unit Tests 15</b></p> <p>What Is Unit Testing? 15</p> <p>What Should You Test? 17</p> <p>Writing Your First Unit Test 17</p> <p>Checking Values with the assertEquals Method 18</p> <p>Checking Exception Handling with assertRaises 20</p> <p>Following the PEP-8 Standard 22</p> <p>Unit Test Structure 23</p> <p>Additional Unit Test Examples 24</p> <p>Getting Clever with assertRaises 24</p> <p>Making Your Life Easier with setUp 25</p> <p>Useful Methods in Unit Testing 27</p> <p>assertEqual(x, y, msg=None) 27</p> <p>assertAlmostEqual(x, y, places=None, msg=None, delta=None) 27</p> <p>assertRaises(exception, method, arguments, msg=None) 28</p> <p>assertDictContainsSubset(expected, actual, msg=None) 28</p> <p>assertDictEqual(d1, d2, msg=None) 28</p> <p>assertTrue(expr, msg=None) 28</p> <p>assertFalse(expr, msg=None) 29</p> <p>assertGreater(a, b, msg=None) 29</p> <p>assertGreaterEqual(a, b, msg=None) 29</p> <p>assertIn(member, container, msg=None) 30</p> <p>assertIs(expr1, expr2) 30</p> <p>assertIsInstance(obj, class, msg=None) 30</p> <p>assertNotIsInstance(obj, class, msg=None) 30</p> <p>assertIsNone(obj, msg=None) 30</p> <p>assertIsNot(expr1, expr2, msg=None) 31</p> <p>assertIsNotNone(obj, msg=None) 31</p> <p>assertLess(a, b, msg=None) 31</p> <p>assertLessEqual(a, b, msg=None) 31</p> <p>assertItemsEqual(a, b, msg=None) 31</p> <p>assertRaises(excClass, callableObj, *args, **kwargs, msg=None) 32</p> <p>Summary 32</p> <p><b>CHAPTER 3 Utilizing Unit Test Tools 33</b></p> <p>Using Python’s Nose 33</p> <p>Installing Nose 34</p> <p>Using Nose’s Best Features 35</p> <p>Running Specifi c Test Files 35</p> <p>Getting More Detail with Verbose 35</p> <p>Debugging Support with PDB 36</p> <p>Checking Your Coverage 38</p> <p>Coloring your tests with Rednose 39</p> <p>PyTest: An Alternative Test Runner 40</p> <p>Installing PyTest 40</p> <p>PyTest’s Best Features 41</p> <p>Running Specifi c Tests 41</p> <p>Viewing Detail with Verbose and Summary 42</p> <p>Debugging with PDB 43</p> <p>Checking Your Coverage with PyTest 45</p> <p>Choosing Between Nose and PyTest 46</p> <p>Mock and Patch Tricky Situations 46</p> <p>Installing the Mock Library 47</p> <p>Mocking a Class and Method Response 47</p> <p>When Mock Won’t Do, Patch! 50</p> <p>The Requests Library 50</p> <p>Patch in Action 50</p> <p>Advanced Mocking 52</p> <p>Summary 53</p> <p><b>CHAPTER 4 Writing Testable Documentation 55</b></p> <p>Writing Your First Doctest 56</p> <p>Th e Python Shell 56</p> <p>Adding Doctests to a Method 57</p> <p>Running Your Doctests 58</p> <p>Handling Error Cases 59</p> <p>Advanced Doctest Usage 61</p> <p>Improving Doctests with Nose Integration 62</p> <p>Summary 65</p> <p>Resources 65</p> <p><b>CHAPTER 5 Driving Your Development with Tests 67</b></p> <p>Agile Development 67</p> <p>Adopting the Agile Process Now 68</p> <p>Ethos of Test Driven Development 70</p> <p>Advantages of Test Driven Development 72</p> <p>Ping-Pong Programming 72</p> <p>Test Driving Your Problem 73</p> <p>Writing Your Failing Test 74</p> <p>Making Your Test Pass 75</p> <p>Driving More Features with Tests 75</p> <p>Wrapping Up the Task 77</p> <p>Summary 82</p> <p>Resources 83</p> <p><b>CHAPTER 6 Writing Acceptance Tests 85</b></p> <p>What Is Acceptance Testing? 85</p> <p>Anatomy of an Acceptance Test 87</p> <p>Using Gherkin Syntax 87</p> <p>Th e Magic Is in the Step File 88</p> <p>Goals of Acceptance Testing 89</p> <p>Implementing Developer and QA Collaboration 90</p> <p>Letting Behavior Drive Your Problem 90</p> <p>Writing Your Failing Acceptance Test 90</p> <p>Defining Your Steps 92</p> <p>Implementing Your Code 94</p> <p>Developing More of the Feature 95</p> <p>bank_apppy 96</p> <p>indexhtml 97</p> <p>Delivering the Finished Article 98</p> <p>Advanced Acceptance Test Techniques 102</p> <p>Scenario Outline 102</p> <p>Tables of Data in Scenarios 103</p> <p>Summary 104</p> <p>Resources 105</p> <p><b>CHAPTER 7 Utilizing Acceptance Test Tools 107</b></p> <p>Cucumber: The Acceptance Test Standard 107</p> <p>Lettuce in Detail 108</p> <p>Tagging 108</p> <p>Fail Fast 112</p> <p>Nosetest Integration 114</p> <p>Robot: An Alternative Test Framework 115</p> <p>Installing Robot 116</p> <p>Writing a Test Case 116</p> <p>Implementing Keywords 117</p> <p>Running Robot Tests 119</p> <p>Summary 123</p> <p>Resources 123</p> <p><b>CHAPTER 8 Maximizing Your Code’s Performance 125</b></p> <p>Understanding the Importance of Performance Testing 126</p> <p>JMeter and Python 126</p> <p>Installation 127</p> <p>Configuring Your Test Plans 128</p> <p>Utilizing Your Test Plans Effectively 135</p> <p>Code Profiling with cProfile 135</p> <p>Run a cProfile Session 136</p> <p>Analyzing the cProfile Output 142</p> <p>Summary 144</p> <p>Resources 144</p> <p><b>CHAPTER 9 Looking After Your Lint 145</b></p> <p>Coming to Grips with Pylint 146</p> <p>Installing Pylint 146</p> <p>Using Pylint 146</p> <p>Understanding the Pylint Report 149</p> <p>The Module Block 149</p> <p>The Messages by Category Section 149</p> <p>The Messages Section 150</p> <p>The Code Evaluation Score 150</p> <p>The Raw Metrics Section 150</p> <p>The Statistics by Type Section 150</p> <p>Customizing Pylint’s Output 150</p> <p>Telling Pylint to Ignore Errors 153</p> <p>Covering All Your Code with Unit Tests 154</p> <p>Installing Coverage 155</p> <p>Using Coverage 155</p> <p>Advanced Coverage Options 157</p> <p>Producing an HTML/XML Report 157</p> <p>Setting a Minimum Coverage Threshold 159</p> <p>Restricting Coverage to a Specific Package 159</p> <p>Ignoring Coverage 160</p> <p>Summary 161</p> <p>Resources 162</p> <p><b>CHAPTER 10 Automating Your Processes 163</b></p> <p>Build Paver Tasks 164</p> <p>Installing Paver 164</p> <p>Creating a Paver Task 164</p> <p>Executing Paver Tasks 165</p> <p>Defi ning a Default Build 166</p> <p>Setting Up Automated Builds 168</p> <p>Installing Jenkins 169</p> <p>Adding Coverage and PyLint Reports 175</p> <p>Generating a PyLint Report 175</p> <p>Generating a Coverage Report 176</p> <p>Making Your Build Status Highly Visible 176</p> <p>Summary 181</p> <p>Resources 181</p> <p><b>CHAPTER 11 Deploying Your Application 183</b></p> <p>Deploying Your Application to Production 184</p> <p>Creating a Deployable Artifact 185</p> <p>Defining the Paver Tasks 185</p> <p>Incorporating Packaging into the Build 187</p> <p>Enabling Archiving on Jenkins 188</p> <p>QA Environment 189</p> <p>Implementing Stage and Production Environments 190</p> <p>Implementing a Cloud Deployment 191</p> <p>Creating a Heroku Account 192</p> <p>Creating a Small Application 193</p> <p>Setting up Git for Heroku 193</p> <p>Deploying the Application to Heroku 194</p> <p>Smoke Testing a Deployed Application 195</p> <p>Example Application Stack 196</p> <p>Smoke Test Scenarios 197</p> <p>Implementing Smoke Tests 198</p> <p>Summary 200</p> <p>Resources 201</p> <p><b>CHAPTER 12 The Future of Testing Python 203</b></p> <p>Stub the Solution 203</p> <p>Making Deployment Natural 205</p> <p>Automating (Nearly) Everything 206</p> <p>Working in Public 207</p> <p>Collaborating on Step Definitions 208</p> <p>Final Thoughts 209</p> <p>Resources 210</p> <p>Index 211</p>
<p><b>David Sale</b> 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.</p>
<ul> <li>Clearly defines testing fundamentals and best practices</li> <li>Provides comprehensive overview of unit testing methods</li> <li>Explains how to implement Test Driven Development</li> <li>Covers acceptance testing and tools needed to perform acceptance tests</li> </ul> <p><b>Apply Acceptance Testing, Test-Driven Development, Unit Testing, and Behavior-Driven Development to Python</b></p> <p>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. More recently, behavior-driven development (BDD) has taken testing to a new level, and this book will introduce you to the practice and tools to take up this exciting modern style of testing your software. 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 to:</p> <ul> <li>Get your hands dirty with the basic building blocks in testing: unit tests</li> <li>Effectively embed unit tests in your doc strings and have them run as tests</li> <li>Adopt the concepts and ethos of test-driven development (TDD)</li> <li>Deploy smoke testing and get to grips with Pylint</li> <li>Write and undertake acceptance testing with Cucumber, Lettuce, and Robot</li> <li>Analyse and find problem areas within your code using JMeter and cProfile</li> <li>Successfully implement continuous integration</li> </ul>

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €