Learning Python Testing

A straightforward and easy approach to testing your Python projects

Learning Python Testing

This ebook is included in a Mapt subscription
Daniel Arbuckle

1 customer reviews
A straightforward and easy approach to testing your Python projects
$0.00
$12.00
$39.99
$29.99p/m after trial
RRP $23.99
RRP $39.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781783553211
Paperback200 pages

Book Description

Automated testing is the best way to increase efficiency and decrease the defects of software testing. It takes away much of the effort on your part so that you can find bugs early and easily. The Python unit testing framework makes it easy to write efficient automated test cases in Python. Applications involving many paradigms and styles can be very complicated to test, but with the right tools, testing becomes the simplest part of the development process.

This book starts with a short introduction to testing, and then introduces the doctest tool, both in terms of practicalities and how it fits into the testing environment. From there, the discussion proceeds to unittest.mock and mock objects, and to unittest. Next, Nose is introduced and discussed. Later on, focus turns from the tools themselves toward best practices and disciplines of testing. Finally, the integration of testing with existing build processes and toolchains is covered. By the end of this book, you will know how to use automated testing quickly and easily and in a way that helps catch bugs early and fix them.

Table of Contents

Chapter 1: Python and Testing
Testing for fun and profit
Levels of testing
Acceptance testing
Regression testing
Test-driven development
You'll need Python
Summary
Chapter 2: Working with doctest
Where doctest performs best
The doctest language
Expecting exceptions
Expecting blank lines
Controlling doctest behavior with directives
Ignoring part of the result
Ignoring white space
Skipping an example
The other directives
The execution scope of doctest tests
Check your understanding
Exercise – English to doctest
Embedding doctests into docstrings
Putting it into practice – an AVL tree
Summary
Chapter 3: Unit Testing with doctest
What is unit testing?
The limitations of unit testing
Check your understanding
Unit testing during the development process
Summary
Chapter 4: Decoupling Units with unittest.mock
Mock objects in general
Mock objects according to unittest.mock
Mock objects in action
Summary
Chapter 5: Structured Testing with unittest
The basics
Assertions
Make sure you get it
Test fixtures
Summary
Chapter 6: Running Your Tests with Nose
Installing Nose
Organizing tests
Simplifying the Nose command line
Customizing Nose's test search
Nose and doctest tests
Nose and unittest tests
Nose and ad hoc tests
Summary
Chapter 7: Test-driven Development Walk-through
Writing the specification
Writing initial unit tests
Coding planner.data
Using tests to get the code right
Writing the persistence tests
Finishing up the personal planner
Summary
Chapter 8: Integration and System Testing
Introduction to integration testing and system testing
Automating integration tests and system tests
Check yourself – writing integration tests
Summary
Chapter 9: Other Tools and Techniques
Code coverage
Version control integration
Automated continuous integration
Summary

What You Will Learn

  • Make testing easy and convenient with powerful tools such as doctest, unittest, and Nose
  • Walk through the test-driven development process step by step
  • Translate specification documents into actionable tests
  • Write tests that highlight exactly where a bug resides
  • Build on the basis of unit testing to be able to test a complete software system
  • Use unit testing to drive development and discover how this can make the process faster

Authors

Table of Contents

Chapter 1: Python and Testing
Testing for fun and profit
Levels of testing
Acceptance testing
Regression testing
Test-driven development
You'll need Python
Summary
Chapter 2: Working with doctest
Where doctest performs best
The doctest language
Expecting exceptions
Expecting blank lines
Controlling doctest behavior with directives
Ignoring part of the result
Ignoring white space
Skipping an example
The other directives
The execution scope of doctest tests
Check your understanding
Exercise – English to doctest
Embedding doctests into docstrings
Putting it into practice – an AVL tree
Summary
Chapter 3: Unit Testing with doctest
What is unit testing?
The limitations of unit testing
Check your understanding
Unit testing during the development process
Summary
Chapter 4: Decoupling Units with unittest.mock
Mock objects in general
Mock objects according to unittest.mock
Mock objects in action
Summary
Chapter 5: Structured Testing with unittest
The basics
Assertions
Make sure you get it
Test fixtures
Summary
Chapter 6: Running Your Tests with Nose
Installing Nose
Organizing tests
Simplifying the Nose command line
Customizing Nose's test search
Nose and doctest tests
Nose and unittest tests
Nose and ad hoc tests
Summary
Chapter 7: Test-driven Development Walk-through
Writing the specification
Writing initial unit tests
Coding planner.data
Using tests to get the code right
Writing the persistence tests
Finishing up the personal planner
Summary
Chapter 8: Integration and System Testing
Introduction to integration testing and system testing
Automating integration tests and system tests
Check yourself – writing integration tests
Summary
Chapter 9: Other Tools and Techniques
Code coverage
Version control integration
Automated continuous integration
Summary

Book Details

ISBN 139781783553211
Paperback200 pages
Read More
From 1 reviews

Read More Reviews