Get startedGet started for free

Testing

1. Testing

In this video, you'll explore the world of testing.

2. Roadmap

Testing the final component in our case study.

3. Why automated testing?

"But what about testing?" you ask a colleague at PyBank. "Does someone need to do all that work manually? What happens when the code is changed? Do you have to re-test everything?" Automated testing is the process of using software tools to run tests on your code automatically, without human intervention. These tests can range from simple checks on individual functions to comprehensive assessments of entire applications

4. Benefits of automated testing

"What are the benefits of testing?" you ask. Your friend tells you three advantages of software testing. Software testing improves code quality by identifying and fixing bugs early, resulting in more reliable and stable code. It also mitigates risks by reducing the chance of unexpected failures in production, ensuring that new updates or features don't introduce new issues. Additionally, testing enhances the user experience by catching and resolving problems before release, leading to smoother and more positive interaction with your software.

5. What Do Unit Tests Do?

You've heard of something called "unit testing." Unit tests are a type of software testing where individual components or functions of a program are tested in isolation to ensure they work correctly. These tests focus on the smallest parts of an application, such as a single function, method, or class. Unit tests verify that each function produces the expected output given specific inputs.

6. What is the pytest library?

`pytest` is a popular testing framework for Python that makes it easy to write simple as well as scalable test cases. It supports unit testing, functional testing, and more complex testing scenarios. `pytest` is known for its simplicity, flexibility, and powerful features, making it a preferred choice for many Python developers.

7. Advantages of pytest

`pytest` offers simplicity and readability, allowing you to write concise and clear tests with minimal overhead. It also provides powerful fixtures, enabling you to set up and reuse test conditions efficiently across multiple tests, which helps reduce code duplication. Additionally, `pytest` is highly extensible, with a vast ecosystem of plugins that allow you to customize the framework to meet your specific testing needs.

8. Unit test - example

Suppose you have a file, `math.py` that contains a function that adds two numbers. To test this file, you write a separate test file, `test_math.py`. To run the test, run `pytest test_math.py` from the console. Pytest runs the tests contained in `test_math.py`. All tests passed!

9. Let's practice!

It's your turn to practice testing code!