Crafting Test-Driven Software with Python: Write test suites that scale with your applications needs and complexity, using Python and PyTest

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Get to grips with essential concepts and step-by-step explanations to apply TDD practices to your Python projects while keeping your test suite under control Key Features • Build robust Python applications using TDD and BDD methodologies • Test Python web applications using WebTest and web frameworks • Leverage PyTest to implement stringent testing mechanisms to ensure fault-tolerant applications Book Description Test-driven development (TDD) is a set of best practices that helps developers to build more scalable software, and is used to increase the robustness of software by using automatic tests. This book shows you how to apply TDD practices efficiently in Python projects. You'll begin by learning about built-in unit tests and Mocks before covering rich frameworks like PyTest and web-based libraries such as WebTest and Robot, and understand how Python allows you to embrace all modern testing practices with ease. Moving on, you'll find out how to design tests and balance them with new feature development and discover how to create a complete test suite with PyTest. The book helps you adopt a hands-on approach to implementing TDD and associated methodologies that will have you up and running and make you more productive in no time. With the help of step-by-step explanations of essential concepts and practical examples, you'll explore automatic tests and TDD best practices and get to grips with the methodologies and tools available in Python for creating effective and robust applications. By the end of this Python book, you will be able to write reliable test suites in Python to ensure the long-term resilience of your application while learning about the range of libraries offered by Python for testing and development. What you will learn • Find out how tests can make your life easier as a developer and discover related best practices • Explore and learn PyTest, the most widespread testing framework for Python • Get to grips with the most common PyTest plugins, including coverage, flaky, xdist, and picked • Write functional tests for WSGI web applications with WebTest • Run end-to-end tests for web applications using the Robot framework • Understand what test-driven development means and why it is important • Discover how to use the range of tools available in Python • Build reliable and robust applications Who This Book Is For This book is for Python developers looking to get started with test-driven development and developers who want to learn about the testing tools available in Python. Developers who want to create web applications with Python and plan to implement TDD methodology with PyTest will find this book useful. Basic knowledge of Python programming is required.

Author(s): Alessandro Molina
Edition: 1
Publisher: Packt Publishing
Year: 2021

Language: English
Commentary: Vector PDF
Pages: 303
City: Birmingham, UK
Tags: Python; Unit Testing; Django; Automation; PyTest; Testing; WebTest; Tox; Pyramid; Test-Driven Development; trophy; Robot Framework

Cover
Title Page
Copyright and Credits
Dedication
Contributors
Table of Contents
Preface
Section 1: Software Testing and Test-Driven Development
Chapter 1: Getting Started with Software Testing
Technical requirements
Introducing software testing and quality control
Test plans
Introducing automatic tests and test suites
Multiple test cases
Organizing tests
Introducing test-driven development and unit tests
Test-driven development
Test units
Understanding integration and functional tests
Integration tests
Functional tests
Understanding the testing pyramid and trophy
The testing pyramid
The testing trophy
Testing distribution and coverage
Summary
Chapter 2: Test Doubles with a Chat Application
Technical requirements
Introducing test doubles
Starting our chat application with TDD
Using dummy objects
Replacing components with stubs
Checking behaviors with spies
Using mocks
Replacing dependencies with fakes
Understanding acceptance tests and doubles
Managing dependencies with dependency injection
Using dependency injection frameworks
Summary
Chapter 3: Test-Driven Development while Creating a TODO List
Technical requirements
Starting projects with TDD
Building applications the TDD way
Preventing regressions
Summary
Chapter 4: Scaling the Test Suite
Technical requirements
Scaling tests
Moving from e2e to functional
Working with multiple suites
Compile suite
Commit tests
Smoke tests
Carrying out performance testing
Enabling continuous integration
Performance testing in the cloud
Summary
Section 2: PyTest for Python Testing
Chapter 5: Introduction to PyTest
Technical requirements
Running tests with PyTest
Writing PyTest fixtures
Using fixtures for dependency injection
Managing temporary data with tmp_path
Testing I/O with capsys
Running subsets of the testsuite
Summary
Chapter 6: Dynamic and Parametric Tests and Fixtures
Technical requirements
Configuring the test suite
Generating fixtures
Generating tests with parametric tests
Summary
Chapter 7: Fitness Function with a Contact Book Application
Technical requirements
Writing acceptance tests
Writing the first test
Getting feedback from the product team
Making the test pass
Using behavior-driven development
Defining a feature file
Declaring the scenario
Running the scenario test
Further setup with the And step
Performing actions with the When step
Assessing conditions with the Then step
Making the scenario pass
Embracing specifications by example
Summary
Chapter 8: PyTest Essential Plugins
Technical requirements
Using pytest-cov for coverage reporting
Coverage as a service
Using pytest-benchmark for benchmarking
Comparing benchmark runs
Using flaky to rerun unstable tests
Using pytest-testmon to rerun tests on code changes
Running tests in parallel with pytest-xdist
Summary
Chapter 9: Managing Test Environments with Tox
Technical requirements
Introducing Tox
Testing multiple Python versions with Tox
Using environments for more than Python versions
Using Tox with Travis
Summary
Chapter 10: Testing Documentation and Property-Based Testing
Technical requirements
Testing documentation
Adding a code-based reference
Writing a verified user guide
Property-based testing
Generating tests for common properties
Summary
Section 3: Testing for the Web
Chapter 11: Testing for the Web: WSGI versus HTTP
Technical requirements
Testing HTTP
Testing HTTP clients
Testing WSGI with WebTest
Using WebTest with web frameworks
Writing Django tests with Django's test client
Testing Django projects with pytest
Testing Django projects with Django's test client
Summary
Chapter 12: End-to-End Testing with the Robot Framework
Technical requirements
Introducing the Robot Framework
Testing with web browsers
Recording the execution of tests
Testing with headless browsers
Testing multiple browsers
Extending the Robot Framework
Adding custom keywords
Extending Robot from Python
Summary
About Packt
Other Books You May Enjoy
Index