Python Unit Test Automation : Automate, Organize, and Execute Unit Tests in Python
معرفی کتاب «Python Unit Test Automation : Automate, Organize, and Execute Unit Tests in Python» نوشتهٔ Ashwin Pajankar و an O'Reilly Media Company Safari، منتشرشده توسط نشر Apress L. P. در سال 2021. این کتاب در 209 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «Python Unit Test Automation : Automate, Organize, and Execute Unit Tests in Python» در دستهٔ برنامهنویسی قرار دارد.
Learn how to automate unit tests of Python 3 with automation libraries, such as doctest, unittest, nose, nose2, pytest, and selenium. This book explores important concepts in software test automation and demonstrates how to automate, organize, and execute unit tests with Python. It also introduces readers to the concepts of web browser automation and logging. This new edition starts with an introduction to Python 3. Next, it covers doctest and pydoc. This is followed by a discussion on unittest, a framework that comes packaged with Python 3 itself. There is a dedicated section on creating test suites, followed by an explanation of how nose2 provides automatic test module discovery. Moving forward, you will learn about pytest, the most popular third-party library and testrunner for Python. You will see how to write and execute tests with pytest. You’ll also learn to discover tests automatically with pytest. This edition features two brand new chapters, the first of which focuses on the basics of web browser automation with Selenium. You’ll learn how to use Selenium with unittest to write test cases for browser automation and use the Selenium IDE with web browsers such as Chrome and Firefox. You’ll then explore logging frameworks such as Python’s built-in logger and the third-party framework loguru. The book concludes with an exploration of test-driven development with pytest, during which you will execute a small project using TDD methodology. What You Will Learn Start testing with doctest and unittest Understand the idea of unit testing Get started with nose 2 and pytest Learn how to use logger and loguru Work with Selenium and test driven development Who This Book Is For Python developers, software testers, open source enthusiasts, and contributors to the Python community. Table of Contents About the Author About the Technical Reviewers Acknowledgments Introduction Why This Book? Who This Book Is For How This Book Is Organized How to Get the Most Out of This Book Where Next? A Quick Word About the Instructors’ Fraternity Chapter 1: Introduction to Python The History of Python Features of Python Simple Easy to Learn Easy to Read Easy to Maintain Open Source High-Level Language Portable Interpreted Object-Oriented Extensible Extensive Libraries Robust Rapid Prototyping Memory Management Powerful Community Support Python 3 Differences Between Python 2 and Python 3 Why Use Python 3 Installing Python 3 Installation on Linux Installation on Debian, Ubuntu, and Derivatives Installation on Fedora and CentOS Installation on macOS X Installation on Windows Running a Python Program and Python Modes Interactive Mode Script Mode IDEs for Python IDLE The PyDev Plugin for Eclipse Geany PyCharm Conclusion Chapter 2: Getting Started A Brief Introduction to Software Testing Concepts Unit Testing Test Automation The Benefits of Automated Unit Testing Using Docstrings Example of a Docstring in Python A Brief Introduction to doctest Failing Tests Separate Test File Advantages and Disadvantages of doctest Pydoc Conclusion Chapter 3: unittest Introduction to xUnit Using unittest Order of Execution of the Test Methods Verbosity Control Multiple Test Classes Within the Same Test File/Module Test Fixtures Running Without unittest.main( ) Controlling the Granularity of Test Execution Listing All the Command-Line Options and Help Important Command-Line Options Creating a Test Package Organizing the Code Placing the Development and Test Code in a Single Directory Placing the Development and Test Code in Separate Directories Test Discovery Coding Conventions for unittest Assertions in unittest Other Useful Methods Failing a Test Exceptions in Test Cases assertRaises( ) Creating Test Suites Creating Test Suites Conclusion Chapter 4: nose and nose2 Introduction to nose Installing nose on Linux Distributions Installing nose on macOS and Windows Verifying the Installation Getting Started with nose A Simple nose Test Case Running the Test Module with nosetests Getting Help Organizing the Test Code Test Discovery Fixtures for Classes, Modules, and Methods Fixtures for Functions Fixtures for Packages Alternate Names of the nose Fixtures assert_equals( ) Testing Tools ok_ and eq_ The @raises() Decorator The @timed() decorator Report Generation Creating an XML Report Creating an HTML Report Creating Color Output in the Console Running unittest Tests from nose Running doctest Tests from nose Advantages of nose over unittest Disadvantages of nose Using nose2 Conclusion Chapter 5: pytest Introduction to pytest Simple Test Running Tests with the py.test Command Test Class and Test Package in pytest Test Discovery in pytest xUnit-Style Fixtures pytest Support for unittest and nose Introduction to pytest Fixtures Scope of pytest Fixtures pytest.raises( ) Important pytest Command-Line Options Help Stopping After the First (or N) Failures Profiling Test Execution Duration JUnit-Style Logs Conclusion Chapter 6: Testing with Selenium Introduction to Selenium Selenium IDE Selenium Webdriver Selenium with Unittest Conclusion Chapter 7: Logging in Python Logging Basics Logging with an OS Manually Logging with File Operations Logging in Python Logging to a File Customizing the Log Message Customizing Logging Operations Rotating a Log File Using Multiple Loggers Logging with Threads Multiple Loggers Writing to the Same Target Logging with loguru Using loguru and the Available Logging Levels Customizing File Retention Customizing Tracing Customizing the Log Message Format and Display Configuring with a Dictionary Conclusion Chapter 8: Tips and Tricks Coding and Filenaming Conventions for Easier Test Discovery Test-Driven Development with pytest Conclusion Index
دانلود کتاب Python Unit Test Automation : Automate, Organize, and Execute Unit Tests in Python