Testing

Testing determines whether software runs correctly based on specific inputs and identifies defects that need to be fixed.

Why is testing important?

As software scales in codebase size, it's impossible for a person or even a large team to keep up with all of the changes and the interactions between the changes. Automated testing is the only proven method for building reliable software once they grow past the point of a simple prototype. Many major software program development failures can be traced back to inadequate or a complete lack of testing.

It's impossible to know whether software works properly unless it is tested. While testing can be done manually, by a user clicking buttons or typing in input, it should be performed automatically by writing software programs that test the application under test.

There are many forms of testing and they should all be used together. When a single function of a program is isolated for testing, that is called unit testing. Testing more than a single function in an application at the same time is known as integration testing. User interface testing ensures the correctness of how a user would interact with the software. There are even more forms of testing that large programs need, such as load testing, database testing, and browser testing (for web applications).

Testing in Python

Python software development culture is heavy on software testing. Because Python is a dynamically-typed language as opposed to a statically-typed language, testing takes on even greater importance for ensuring program correctness.

Python testing tools

The Python ecosystem has a wealth of tools to make it easier to run your tests and interpret the results. The following tools encompass test runners, coverage reports and related libraries.

  • green is a test runner that has pretty printing on output to make the results easier to read and understand.

  • requestium merges the Requests library with Selenium to make it easier to run automated browser tests.

  • coverage.py is a tool for measuring code coverage when running tests.

Testing resources

Mocking resources

Mocking allows you to isolate parts of your code under test and avoid areas that are not critical to the tests you are writing. For example, you may want to test how you handle text message responses but do not want to actually receive text messages in your application. You can mock a part of the code that would provide a happy-path scenario so you can run your tests properly. The following resources show you how to use mocks in your test cases.

测试您的应用程序后会发生什么?

我应该注意哪些代码度量?

我可以自动为我的应用程序进行测试和部署吗?

我想通过网络分析了解有关应用用户的更多信息。

Sign up for a monthly email with Full Stack Python tutorials. No spam ever.

Sponsored By

Rollbar logo

Fix errors in your Python code before your users see them by monitoring with Rollbar.

Learn More Python

Introduction to Ansible video course logo.

Deploy web apps with the Ansible configuration management tool.


TestDriven logo

Build microservices with Docker, Flask & React in this great course.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via newsletter, Twitter & Facebook.