Register to get access to free programming courses with interactive exercises

Introduction Python: Automated testing

Professional developers' code contains fewer bugs than novices', but it's not because they're brighter, more detail-oriented, or able to see the code from bean to cup. The real reason is that they write tests.

Automated testing is an integral part of the programming process in a professional environment. Tests are the only reliable way to make sure your code works. They don't eliminate bugs, but they help you keep the number of bugs at an acceptable level. Tests check that changes to one part of the system haven't broken other parts.

But tests are needed for more than just checking that the code works. There are other types of automated tests, such as performance or vulnerability tests. First of all, programmers are responsible for functional tests. These tests verify that the code performs its intended task from program users' perspective, for example:

  • To check if the programmer has written some code that's responsible for user registration
  • To carry out a functional test that shows whether the user can register

According to the degree of isolation of the tested parts of the code, functional tests fall into three general categories:

  • Unit tests. They are simple but not very effective. They check the functionality of functions or other specific modules in the program
  • Integration tests. They cover most of the system and check whether the modules work together. Programmers pay the most amount of attention to these tests. Integration tests are still easy to write if you prepare the ecosystem
  • System tests. These are the most effective tests but are also challenging to write and maintain. They emulate user behavior, such as clicking on links and sending forms. These tests often fail because they rely on site layout, which can change unpredictably. Even with this kind of testing, it's impossible to determine when, from the program's perspective, one action ended and another began

Despite the differences, all automated tests lean on the same principles and often use the same tools. This course introduces the general principles of testing and takes you step by step through all the tasks that arise during testing. We'll touch on the following main topics during the course:

  • Asserts
  • Testing Frameworks (Pytest)
  • Unit testing
  • Covering code with tests
  • Test-driven development (TDD)

How to prepare for this course

Testing is an integral part of the development process. To start studying this topic, you need to master the basic syntax of the programming language, working with collections and functions. You should review the fundamentals of setting up the Python environment and modularity again. We cover these topics in detail in the following courses:


Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>
Suggested learning programs
profession
new
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.