How to write unit test before class code?

I am trying to get used to writing unit test before the actual class. What are some pointers that the community can provide me with any useful resources.

thank

+3
source share
4 answers

The idea of ​​writing a test in the first place is that you know what the code will do before you write. So, you make a list of what you want and how you want each function to be used. Then you write a test for each function (feel free to write more than one or how much is needed to test the functionality of the object.)

. , , , . , .

Boom - Test Driven Development !: -)

+2

:

, , .

- , ( , ).

0

I generally do my TDD (with PHPUnit), creating a set of business rules as part of PHPDocs for my class or script. I do not write code, only business rules (for example, Foo will throw an exception if ... etc.). After I do this, I start writing tests that match each business rule. I found that writing business rules first helps me set some boundaries, and test cases form the actual code.

0
source

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


All Articles