>

September 6, 2020

Why testing is important

Other pytest articles:

Why testing is important

Types of tests

Test driven Development

Hello, World!

Selecting tests with pytest

Testing HTTP client with pytest

Testing database with pytest

Advanced fixtures with pytest

Pytest plugins

Testing makes our code flexible, reliable and reusable.

Flexible

If you don’t have tests for your code - every change to the code is a possible bug. Thus, developers fear making changes and implementing new features, no matter how flexible the architecture of the application is.

But with tests, the developers are free from this fear. The more quality tests you have that cover most of the codebase, the less you fear.

You can make changes to the code that even has less than ideal architecture and opaque design. Moreover, with tests, you can gradually improve these irregularities without worrying about breaking changes. All this makes your code more flexible and open to changes.

Reliable

Tests can assess application reliability. Many developers rely on testing as a quality assessment and improvement technique.

However, tests have moderate error detection rate - about 50%. And with the tests, you cannot prove that there are no errors. If you found a thousand bugs - are you sure that there are no more than that. Also, an absence of errors could mean weak or ineffective test cases.

But nevertheless, you can use the test results to answer the question of how reliable your application is. Even if you never correct the defects that testing finds. Another use for the results is that they can and usually do guide corrections to the software.

Finally, over time, defects found by tests can show the most common bugs and ways to avoid them in the future by designing future test cases, directing code review and so on.

Reusable

Many developers when start to work with a new framework look through provided code examples, because only code will tell you the truth. If you want to know how to use code you need to read code.

Each of the tests you write is an example, written in code, describing how the system should be used. There will be a unit test that describes how to create every object in the system, how to call every function. For anything you need to know how to do, there will be a unit test that describes it in detail.

The tests are documents. They describe the lowest-level design of the system. They are unambiguous, accurate, written in a language that the audience understands, and up-to-date.

They are the best kind of low-level documentation that can exist allowing other developers to reuse your code.

In this unit you’ve learned why tests are important. In the next one we’ll cover what types of tests are there.

Support the author - Buy me a coffee!

Comments powered by Talkyard.

© Alexey Smirnov 2021