T
T
TedMosby2012-05-21 20:12:52
PHP
TedMosby, 2012-05-21 20:12:52

Automatic test generation for PHP

Here's the idea. For each function (method) that needs a unit test, the programmer leaves the @needTest tag in the DOC comment. After that, when the script is executed, a special module monitors all launches of this function and remembers which arguments have which return value. Based on this data, the module automatically builds unit tests (PHPUnit). As if fixes the correct operation of the application at the moment. After that, you can do refactoring or whatever.

Are there already such solutions? And do you think it makes sense?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
R
rPman, 2012-05-21
@rPman

In general, as an assistant for writing tests, such a module would be quite good, not an absolute solution, but it would completely automate a bunch of dreary work.

S
Sergey Ozeransky, 2012-05-21
@KREGI

habrahabr.ru/post/144168/ ?

D
DeadMoroz, 2012-05-21
@DeadMoroz

What about the meaning? Tests should document the code, describing the various uses for it. If you generate tests by code, how will the generator understand what exactly you wanted from the code? According to the crooked code, crooked tests will be generated, and the code will not become smoother from this.

D
Davert, 2012-05-21
@Davert

Generate file ok.
But this is nonsense:
отслеживает все запуски этой функции и запоминает при каких аргументах какое возвращаемое значение. По этим данным модуль автоматически строит unit-тесты (PHPUnit). Как бы фиксирует корректную работу приложения в данный момент.
The work of 90% of the methods cannot be checked by comparing input / output
The method may not return anything at all, but it can call a bunch of other methods from itself. You will not track their correct work in any way. Only write by hand.

V
Vyacheslav Plisko, 2012-05-21
@AmdY

Netbeans has built-in static test generation, unfortunately without regenerating as it changes.

A
AxisPod, 2012-05-22
@AxisPod

Why do you need a test generator? Maybe you need a program code generator, which is enough to say: “I want a program”, the generator will read thoughts, drive into the future, look at the most correct scenario and give you a finished program.
Automatic generation of tests based on the generated code is some kind of nonsense.

E
EugeneOZ, 2012-05-22
@EugeneOZ

a test failure will mean nothing - it will be more likely that the test was generated crookedly. The success of the test will also mean nothing, for the same reason. And the elimination of dependencies is not always a trivial task for a person, and even for a program in general, IMHO, unsolvable in our time, because. the program will have to program, create mocks, stubs ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question