G
G
German Zvonchuk2014-04-16 21:42:49
PHP
German Zvonchuk, 2014-04-16 21:42:49

Where to start and how to write unit tests for projects in PHP?

Good day!
I would be very grateful if you share with me Best Practice on the topic of writing Unit tests.
Absolutely everything about code testing is interesting, since lately I have more and more often encountered problems in working code after refactoring or adding new functionality.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Lissitzky, 2014-04-17
@janson

1. install PHPUnit
2. learn how to run PHPUnit tests. The most banal according to the manual. Just run and understand how they work.
3. test the approach on small training problems (any code-kata will do, problems like FizzBuzz, a temperature converter from Celsius to Fahrenheit, any simple, algorithmic tasks with a verifiable result).
4. After understanding the essence of the tests, we start tests / in a real project, and start thinking about how to start it all. For the first time, it is quite difficult to figure out how to combine all this goodness. Gradually we fasten tests, master the technique of working with stubs (Stub) and mocks (Mock).
In the process of mastering step #3, try out TDD: before writing the code that solves the problem, we write tests for future code. This will require in the process of writing a test to think about how classes, methods, functions will be called, what are the boundary conditions for passing tests, and so on.
It is very likely that not everything will be clear and simple the first time. Try.
As food for thought and mastering the TDD methodology, a selection of tasks:
codekata.com
In many of them, even the conditions of the tests are prescribed, it remains to be corrected for themselves and set to implementation.

Z
Zaur Ashurbekov, 2014-04-16
@zaurius

Tests first, code later! The principle is called test-driven development (TDD) .
Good article on Habré

1
1001001 111, 2014-04-17
@IgorO2

phpunit.de/manual/current/en/index.html

A
Alexander, 2014-04-16
@disc

Try this:
Translation by phptherightway
Original by phptherightway

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question