Unit Testing with Python 3
Unit testing is a great way to foster quality and enhance collaboration with other developers. Learn to write unit tests in good style using popular frameworks like unittest and pytest.
What you'll learn
Once you’ve learned the basics of the Python language and started building programs, you will soon realize a need for some automated tests to make sure everything you’ve built keeps on working as you (and other developers) extend and improve it. In this course, Unit Testing with Python, you will learn foundational knowledge in unit testing. First, you will discover how to write and run tests using the ‘unittest’ framework, and some theory about how to design good test cases. Next, you will explore other popular testing frameworks in Python - pytest and doctest. Finally, you will examine how to use test doubles effectively, and techniques for parameterized testing and measuring test coverage. When you’re finished with this course, you will have the skills and knowledge of writing unit tests needed to be confident adding tests for the code you write, and sharing those tests with other developers.
Table of contents
- Version Check 0m
- What Is a Unit Test? 3m
- First Example Unit Test 4m
- Explanation of 'Test Case' and 'Test Runner' 4m
- Exception Checking with assertRaises & Explaination of 'Test Suite' 2m
- Skipping a Test Case & Explanation of 'Test Fixture' 5m
- Vocabulary Summary 1m
- Example of Poor Unit Test Design 5m
- Better Design with Arrange-Act-Assert 3m
- Detailed Design of Arrange-Act-Assert Test Parts 3m
- Module Summary 1m
- Introducing the Module Topics - Why and When 1m
- Unit Testing Helps You to Understand What to Build 3m
- Unit Testing Helps You to Document the Units 2m
- Unit Testing Helps You with Design 4m
- Unit Testing Helps You Detect Regression 3m
- Limitations of Unit Testing 2m
- Unit Testing Is Part of Your Job 2m
- Test-Last Process 2m
- Test-First Process 2m
- Test-Driven Development 2m
- Automated Build Servers and Continuous Integration 4m
- Module Summary 1m
- Introducing pytest - a Popular Alternative to unittest 3m
- First Test Case and Failure Analysis 3m
- Using PyCharm's Test Runner 2m
- Additional Kinds of Assertion, Including assertRaises 3m
- Introduction to Test Fixtures 3m
- Cleaning up Fixture Resources, Chaining Fixtures 4m
- Organzing Test Code for Larger Programs 4m
- Using Markers to Control Which Tests Are Run 4m
- Using an HTML Report Plugin & Module Summary 2m
- Introducing doctest - Embed Unit Tests in Your Docstrings 3m
- Introduction to Yatzy Example & a First doctest 3m
- Using a Test Runner to Execute Your Doctests 2m
- Interpreting Test Failures and Updating Your Docstring 2m
- Handling Output That Varies Using a Wildcard 4m
- Handling Random Numbers, Dictionaries, Floats, and Tracebacks 4m
- Global Options and Directives 3m
- Regression Testing Your Tutorial Documentation 4m
- Module Summary 1m
- What Is a Test Double? 2m
- Example Using a Stub 4m
- Creating a Stub Using unittest.Mock 2m
- Example Using a Fake 5m
- Example Using a Dummy 3m
- Mocks and Spies Give You a Third Kind of Assertion 2m
- Example Using a Spy 6m
- Example Using a Mock 4m
- Overview of All the Types of Test Double 2m
- Using Monkeypatching to Insert a Test Double 4m
- Example Using Monkeypatching to Replace a Built-in Function 3m
- Module Summary 1m
- Module Introduction 0m
- Example Using Parameterized Tests with pytest 3m
- Example Using Parameterized Tests with unittest 2m
- Example Measuring Test Coverage 3m
- Example Measuring Branch Coverage 3m
- Example Adding Parameterized Tests to Existing Code with Coverage 6m
- Tracking Coverage Trends 2m
- Good Uses for Coverage, and Alternatives for Assessing Test Quality 3m
- Module Summary 1m