The purpose of unit testing and TDD: find / minimize errors or improve design?

I am pretty green for unit testing and TDD, so please bear with me, as I ask that some may consider new products, or if discussed previously. If this proves to be a “bad question” (too subjective and open to discussion), I will gladly close it. However, I searched a couple of days and don’t get a final answer, and I need to understand this better, so I don’t know a better way to get more information than to post here.

I started reading an older book on unit testing (because a colleague had it at hand), and her introductory chapter discusses why before unit test. One of the things he does is that in the end, your code is much more reliable and cleaner, and less error prone. He also points out that effective unit testing will make it easier to track and fix bugs. Thus, it seems that you are completely focused on the general prevention / reduction of errors in your code.

On the other hand, I also found an article about writing great unit tests, and it says that the purpose of unit testing is to make your design more robust, and, conversely, finding bugs is the goal of manual testing, not unit testing. .

So, being new to TDD, which I am, I am a little confused about the state of mind with which I have to go to TDD and build my unit tests. I admit that part of the reason I am taking it now with my recently launched project is that I am tired of changes that violate pre-existing code. And, admittedly, the related article at least points to this as an advantage of TDD. But I hope that returning and adding unit tests to my existing code (and then continuing TDD from this point forward) will help prevent these errors in the first place.

Does this book and this article really say the same thing in different tones, or is there some kind of subjectivity on this issue, and what I see are just two people who have slightly different views on how to approach TDD?

Thanks in advance.

+5
7

.

Unit test . , . - . unit test . ( -, if, switch ..). , , . , .. , , - null , , .. API.

, . ? - , ? , ? , ? ? :

  • . , , ( ).
  • , ? - . ? , / , , . , , , . , . , . .

? /mocks, /, , , , . , , . - .

. - , , , , . , . , .

? , . , , , . . , , , . , , ​​ .

, SW . , , , - . , SW , , - , , / - ( ).

TDD? TDD , TDD , , .

+4

. "/ " .

TDD, ( "" ) - .

, ?

  • .
  • .

, . , TDD , . ; .

+3

, . :

API, ( ) , (TDD, ), , API . API, API - " ". :

  • API, " ".
  • TDD- API - , , API "" .
  • API
  • .

, , , , . , , , , . , - .

- , API, , . API , , , . , , " ", - - . "" , .

- , API . , TDD...

+2

, : .

, TDD : , , - .

: UI. , , - , /, MVP/MVC/ .

. SOLID.

, , unit test , ( , ..), . , .

+2

Unit Testing TDD. Unit Testing - "" , .

TDD - , ( ), ( ), . , .

, , . "" , . , "" .

, , , - , , . : - . - , . , .

+1

. Unit test, .

0

, , . , . ( ), ( ).

, TDD - , . , Red-Green-Refactor , . , .

TDD , . . , . TDD , , , , . , TDD - - .

0

All Articles