📜 ⬆️ ⬇️

I want to write tests

image I always read articles about testing code with interest. And I really want to use tests in my projects.
But I can not. I can not find an incentive for myself.

Yes, tests from examples are written almost instantly. But is it necessary to write a test for the function
def get_word(): return 'word' 

The question is quite complicated. To write it will not be a problem, but there will be no tangible benefit from it.
Write such a test to get the joy of +1 completed test? I do not see the point.
To increase test coverage? I do not see the point.
Just?…

With tests, everything is fine, as long as they are from educational articles. But tests are needed for more complex operations:
For example, on one project, parsing other sites is used. Text information and pictures are taken from them in large numbers, work reports are sent, etc.
Here for this process I would like to write tests.

But it makes no sense to write small tests for each function. So they work well.
')
I understand that the previous line causes resentment. But in reality, the function, which, for example, downloads an image and stores it in the repository, is elementary, and there will be no errors (more precisely, these errors are too obvious). Errors appear when using this function (storage is not available, the image processor did not work, etc.).
Moreover, testing all these functions separately does not speak about anything - the processor perfectly processes a thousand images, the storage can withstand more operations than is required. All this, of course, is checked in the function itself, but this does not concern tests.

It is necessary to check the interaction of all functions.
This is what I want. Run the tests and be sure that the rather complex parallelized process runs correctly.
But to write a test for this whole process (we created child processes, downloaded pages, found necessary information, downloaded pictures, converted pictures, validated data, saved data, checked data for integrity, saved reports, etc.), you need to spend a lot of time .
An error can only happen with the interaction of functions. Moreover, the test data does not check these vulnerabilities at all (that on some sites bmp files are stored in jpeg files, you can test, but why, if the function still needs to make an exception and it will work?).
You can create huge arrays of test data to verify these errors, but even here lies the problem. If the error appeared once, then we just fix the function, why do we need to write a test for this error? She will be no more!

It turns out this problem:
I want to write tests, but there is no return from them. Time to write is wasted. It makes no sense to check what is already working (based on experience - we are not breaking what is already working. Well, somehow it happened). For each new case, create a test, fix a problem, check? What is the point in this double spelling of the same thing? The error has already been fixed, write a test that will cover many times more than this error does not work, and checking with single test data from all possible is not particularly useful. The number of possible errors will not decrease at times. Maximum interest.

Yes, there is one more important factor: customers will not understand.

I can not tell the customer that the price of the product will be higher due to the writing of tests.
I can not put the price for the project above, the customer will go to competitors.
I can not change the price because of the tests, I want to earn something.

The customer does not care about tests, stability, everything except the final result. He cannot explain that this product with tests will be better than without them, since it will be more stable, scalable, etc. He doesn't care about that. He needs a result. Quickly. And as cheap as possible.

Of course, I hope this applies only to our field - web programming. For systems related to money turnover, systems on which people's lives depend, etc. tests are required, and there customers will understand that they are needed. I believe in it.

Source: https://habr.com/ru/post/177799/


All Articles