Home Page Icon
Home Page
Table of Contents for
Table of Contents
Close
Table of Contents
by Daniel Arbuckle
Learning Python Testing
Learning Python Testing
Table of Contents
Learning Python Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Python and Testing
Testing for fun and profit
Levels of testing
Unit testing
Integration testing
System testing
Acceptance testing
Regression testing
Test-driven development
You'll need Python
Summary
2. Working with doctest
Where doctest performs best
The doctest language
Example – creating and running a simple doctest
Result – three times three does not equal ten
The syntax of doctests
Example – a more complex test
Result – five tests run
Expecting exceptions
Example – checking for an exception
Result – success at failing
Expecting blank lines
Controlling doctest behavior with directives
Ignoring part of the result
Example – ellipsis test drive
Result – ellipsis elides
Ignoring white space
Example – invoking normality
Result – white space matches any other white space
Skipping an example
Example – humans only
Result – it looks like a test, but it's not
The other directives
The execution scope of doctest tests
Check your understanding
Exercise – English to doctest
Embedding doctests into docstrings
Example – a doctest in a docstring
Result – the code is now self-documenting and self-testable
Putting it into practice – an AVL tree
English specification
Node data
Testing the constructor
Recalculating height
Making a node deletable
Rotation
Locating a node
The rest of the specification
Summary
3. Unit Testing with doctest
What is unit testing?
The limitations of unit testing
Example – identifying units
Choosing units
Check your understanding
Unit testing during the development process
Design
Development
Feedback
Development, again
Later stages of the process
Summary
4. Decoupling Units with unittest.mock
Mock objects in general
Mock objects according to unittest.mock
Standard mock objects
Non-mock attributes
Non-mock return values and raising exceptions
Mocking class or function details
Mocking function or method side effects
Mocking containers and objects with a special behavior
Mock objects for properties and descriptors
Mocking file objects
Replacing real code with mock objects
Mock objects in action
Better PID tests
Patching time.time
Decoupling from the constructor
Summary
5. Structured Testing with unittest
The basics
Assertions
The assertTrue method
The assertFalse method
The assertEqual method
The assertNotEqual method
The assertAlmostEqual method
The assertNotAlmostEqual method
The assertIs and assertIsNot methods
The assertIsNone and assertIsNotNone methods
The assertIn and assertNotIn methods
The assertIsInstance and assertNotIsInstance methods
The assertRaises method
The fail method
Make sure you get it
Test fixtures
Example – testing database-backed units
Summary
6. Running Your Tests with Nose
Installing Nose
Organizing tests
An example of organizing tests
Simplifying the Nose command line
Customizing Nose's test search
Check your understanding
Practicing Nose
Nose and doctest tests
Nose and unittest tests
Module fixture practice
Package fixture practice
Nose and ad hoc tests
Summary
7. Test-driven Development Walk-through
Writing the specification
Try it for yourself – what are you going to do?
Wrapping up the specification
Writing initial unit tests
Try it for yourself – write your early unit tests
Wrapping up the initial unit tests
Coding planner.data
Using tests to get the code right
Try it for yourself – writing and debugging code
Writing the persistence tests
Finishing up the personal planner
Summary
8. Integration and System Testing
Introduction to integration testing and system testing
Deciding on an integration order
Automating integration tests and system tests
Writing integration tests for the time planner
Check yourself – writing integration tests
Summary
9. Other Tools and Techniques
Code coverage
Installing coverage.py
Using coverage.py with Nose
Version control integration
Git
Example test-runner hook
Subversion
Mercurial
Bazaar
Automated continuous integration
Buildbot
Setup
Using Buildbot
Summary
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Learning Python Testing
Table of Contents
Learning Python Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Python and Testing
Testing for fun and profit
Levels of testing
Unit testing
Integration testing
System testing
Acceptance testing
Regression testing
Test-driven development
You'll need Python
Summary
2. Working with doctest
Where doctest performs best
The doctest language
Example – creating and running a simple doctest
Result – three times three does not equal ten
The syntax of doctests
Example – a more complex test
Result – five tests run
Expecting exceptions
Example – checking for an exception
Result – success at failing
Expecting blank lines
Controlling doctest behavior with directives
Ignoring part of the result
Example – ellipsis test drive
Result – ellipsis elides
Ignoring white space
Example – invoking normality
Result – white space matches any other white space
Skipping an example
Example – humans only
Result – it looks like a test, but it's not
The other directives
The execution scope of doctest tests
Check your understanding
Exercise – English to doctest
Embedding doctests into docstrings
Example – a doctest in a docstring
Result – the code is now self-documenting and self-testable
Putting it into practice – an AVL tree
English specification
Node data
Testing the constructor
Recalculating height
Making a node deletable
Rotation
Locating a node
The rest of the specification
Summary
3. Unit Testing with doctest
What is unit testing?
The limitations of unit testing
Example – identifying units
Choosing units
Check your understanding
Unit testing during the development process
Design
Development
Feedback
Development, again
Later stages of the process
Summary
4. Decoupling Units with unittest.mock
Mock objects in general
Mock objects according to unittest.mock
Standard mock objects
Non-mock attributes
Non-mock return values and raising exceptions
Mocking class or function details
Mocking function or method side effects
Mocking containers and objects with a special behavior
Mock objects for properties and descriptors
Mocking file objects
Replacing real code with mock objects
Mock objects in action
Better PID tests
Patching time.time
Decoupling from the constructor
Summary
5. Structured Testing with unittest
The basics
Assertions
The assertTrue method
The assertFalse method
The assertEqual method
The assertNotEqual method
The assertAlmostEqual method
The assertNotAlmostEqual method
The assertIs and assertIsNot methods
The assertIsNone and assertIsNotNone methods
The assertIn and assertNotIn methods
The assertIsInstance and assertNotIsInstance methods
The assertRaises method
The fail method
Make sure you get it
Test fixtures
Example – testing database-backed units
Summary
6. Running Your Tests with Nose
Installing Nose
Organizing tests
An example of organizing tests
Simplifying the Nose command line
Customizing Nose's test search
Check your understanding
Practicing Nose
Nose and doctest tests
Nose and unittest tests
Module fixture practice
Package fixture practice
Nose and ad hoc tests
Summary
7. Test-driven Development Walk-through
Writing the specification
Try it for yourself – what are you going to do?
Wrapping up the specification
Writing initial unit tests
Try it for yourself – write your early unit tests
Wrapping up the initial unit tests
Coding planner.data
Using tests to get the code right
Try it for yourself – writing and debugging code
Writing the persistence tests
Finishing up the personal planner
Summary
8. Integration and System Testing
Introduction to integration testing and system testing
Deciding on an integration order
Automating integration tests and system tests
Writing integration tests for the time planner
Check yourself – writing integration tests
Summary
9. Other Tools and Techniques
Code coverage
Installing coverage.py
Using coverage.py with Nose
Version control integration
Git
Example test-runner hook
Subversion
Mercurial
Bazaar
Automated continuous integration
Buildbot
Setup
Using Buildbot
Summary
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset