P
P
P7472020-09-22 14:55:47
Unit testing
P747, 2020-09-22 14:55:47

What is the point of unit tests?

Good afternoon!

I confess honestly, I never wrote them, I read only articles. I don’t understand why unit tests are needed if you test all the code manually anyway. You can just get by with tracing, strong typing, catching exceptions, "var_dump" is enough for the eyes. I understand if this is all done by artificial intelligence

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-09-22
@P747

Today you wrote one very cool module. Manually tested it and all is well.
After half a year, you write another module that somehow indirectly affects the first one. The first module is broken.
If the application is large, then it is physically impossible to check its performance every time from and to. And Unit tests help ensure that each individual unit behaves predictably in unpredictable situations.
UPD
A simpler example from my own experience:
I wrote a system that analyzes the last actions of the user and generates recommendations for him.
There is an input data set. Looking at it, the developer easily determines what recommendations should be the output.
An algorithm is written that generates these recommendations. The algorithm is large and complex.
Several simple tests are written that simply check that for a given set of input parameters, the final result is the one that was expected.
Later, this algorithm can be reworked and optimized as much as you like: you have an automated system that checks not so much the "operability" as the "relevance" of the output result.

J
jazzus, 2020-09-23
@jazzus

As a fan of tests, I consider it my duty to check in here. I will say this. Covering existing functionality with tests sucks)) It's a boring routine. I use tests exclusively in TDD mode. I write before development. And I recommend this method. And last but not least, testing. Tests are the best TK on which you can’t cheat. You set a difficult task for yourself in the tests, describe the result and the tests don’t care how you achieve it. The development process itself becomes much more interesting. In general, at first I write tests on paper with a pen)) Well, not the acerts themselves, of course, but such a table of contents from the tasks. then the code. And when a feature is written in tests, only then I start development (I don’t even think about the front). You just run tests and write code until they turn green. You write easily, quickly and with a free head. Well, the fact that the tests will test your code in the future, that you can drastically refactor the logic and even the architecture, is understandable. And the fact that this is the most up-to-date documentation. This is pop. In short, I tried it as tests, I didn’t write a single feature without tests. It is not even clear where to start writing code if there are no tests. Routes to write or button.. Horror. In short, I recommend it as one of the most important processes in programming. I do not recommend writing tests after the functional - it is very boring, not effective, most likely you will lose interest and score. tdd only Routes to write or button.. Horror. In short, I recommend it as one of the most important processes in programming. I do not recommend writing tests after the functional - it is very boring, not effective, most likely you will lose interest and score. tdd only Routes to write or button.. Horror. In short, I recommend it as one of the most important processes in programming. I do not recommend writing tests after the functional - it is very boring, not effective, most likely you will lose interest and score. tdd only

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question