Python Testing Cookbook.: Easy solutions to test your Python projects using test-driven development and Selenium, 2nd Edition

Greg L. Turnquist, Bhaskar N. Das

相關主題

商品描述

Fix everyday testing problems in Python with the help of this solution-based guide

Key Features

  • Use powerful tools such as doctest and unittest to make testing convenient
  • Apply automation testing to an existing legacy system that isn't test oriented
  • A practical guide to ease testing in Python using real-world examples

Book Description

Automated testing is the best way to increase efficiency while reducing the defects of software testing. It helps find bugs in code easily and at an early stage so that they can be tackled efficiently. This book delves into essential testing concepts used in Python to help you build robust and maintainable code.

Python Testing Cookbook begins with a brief introduction to Python's unit testing framework to help you write automated test cases. You will learn how to write suitable test sets for your software and run automated test suites with Nose. You will then work with the unittest.mock library, which allows you to replace the parts of your system that are being tested with mock objects and make assertions about how they have been used. You will also see how to apply Test-driven Development (TDD) and Behavior-driven Development (BDD) and how to eliminate issues caused by TDD. The book explains how to integrate automated tests using Continuous Integration and perform smoke/load testing. It also covers best practices and will help you solve persistent testing issues in Python. The book concludes by helping you understand how doctest works and how Selenium can be used to test code efficiently.

What you will learn

  • Run test cases from the command line with increased verbosity
  • Write a Nose extension to pick tests based on regular expressions
  • Create testable documentation using doctest
  • Use Selenium to test the Web User Interface
  • Write a testable story with Voidspace Mock and Nose
  • Configure TeamCity to run Python tests on commit
  • Update project-level scripts to provide coverage reports

Who This Book Is For

If you're a Python developer who wants to take testing to the next level and would like to expand your testing skills, this book is for you. It is assumed that you have some Python programming knowledge.

Table of Contents

  1. USING UNITTEST TO DEVELOP BASIC TESTS
  2. RUNNING AUTOMATED TEST SUITES WITH NOSE
  3. CREATING TESTABLE DOCUMENTATION WITH DOCTEST
  4. TESTING CUSTOMER STORIES WITH BEHAVIOR DRIVEN DEVELOPMENT
  5. HIGH LEVEL CUSTOMER SCENARIOS WITH ACCEPTANCE TESTING
  6. INTEGRATING AUTOMATED TESTS WITH CONTINUOUS INTEGRATION
  7. MEASURING YOUR SUCCESS WITH TEST COVERAGE
  8. SMOKE/LOAD TESTING―TESTING MAJOR PARTS
  9. GOOD TEST HABITS FOR NEW AND LEGACY SYSTEMS
  10. Web UI testing using Selenium

商品描述(中文翻譯)

使用這個基於解決方案的指南,解決Python中的日常測試問題。

主要特點:
- 使用強大的工具,如doctest和unittest,使測試變得方便
- 將自動化測試應用於不以測試為導向的現有遺留系統
- 使用真實世界的例子,提供測試Python的實用指南

書籍描述:
自動化測試是提高效率並減少軟體測試缺陷的最佳方法。它有助於輕鬆地在代碼中找到錯誤並在早期階段解決它們。本書深入探討了Python中使用的基本測試概念,幫助您構建堅固且易於維護的代碼。

《Python測試食譜》首先簡要介紹了Python的單元測試框架,以幫助您編寫自動化測試用例。您將學習如何為軟體編寫適當的測試集,並使用Nose運行自動化測試套件。然後,您將使用unittest.mock庫,該庫允許您將正在測試的系統部分替換為模擬對象並對其使用情況進行斷言。您還將了解如何應用測試驅動開發(TDD)和行為驅動開發(BDD),以及如何消除TDD引起的問題。本書還解釋了如何使用持續集成集成自動化測試並進行煙測/負載測試。它還涵蓋了最佳實踐,並將幫助您解決Python中持續存在的測試問題。本書最後幫助您了解doctest的工作原理以及如何使用Selenium高效測試代碼。

你將學到什麼:
- 使用命令行運行測試用例並增加詳細程度
- 編寫一個Nose擴展,根據正則表達式選擇測試
- 使用doctest創建可測試的文檔
- 使用Selenium測試Web用戶界面
- 使用Voidspace Mock和Nose編寫可測試的故事
- 配置TeamCity在提交時運行Python測試
- 更新項目級別的腳本以提供覆蓋率報告

本書適合對測試有興趣並希望提升測試技能的Python開發人員。假設您具有一些Python編程知識。

目錄:
1. 使用unittest開發基本測試
2. 使用Nose運行自動化測試套件
3. 使用doctest創建可測試的文檔
4. 使用行為驅動開發測試客戶故事
5. 使用接受測試測試高層級客戶場景
6. 將自動化測試與持續集成集成
7. 使用測試覆蓋率衡量您的成功
8. 煙測/負載測試-測試主要部分
9. 新舊系統的良好測試習慣
10. 使用Selenium進行Web界面測試