A tool for automatically creating PHPUnit tests?

I was wondering - is there a tool that will look at my PHP code and automatically generate a PHPUnit test for it? Or is there such a tool for any other language that I could port to PHP?

I'm not talking about creating a skeleton. I thought it would be possible for the tool to look at tokenized PHP and determine code paths through a method, and then automatically generate a test for each code path, creating mocks and setting up β€œpending” calls as needed.

Even if there is no tool that currently does this, can such a task be feasible or am I missing something?

+6
source share
3 answers

It turns out there is no tool that does this at the moment, so I wrote one (with the help of my colleagues). Not complete - enough to explore the concept. Using nikic PHP-Parser ( https://github.com/nikic/PHP-Parser ), you can find all method calls in class methods, and then mocks can be created for them.

At the very least, I may eventually end up to the point where I can use it to run individual test tests.

+4
source

Hardly possible.

Modern methods of automatic test generation depend on the availability of specifications for code behavior, and not just for implementation. Deriving a specification from PHP code is not always easy for a person, not to mention a machine, so I seriously doubt that this work could be done for any real code.

+2
source

I don’t know if you want an external tool to generate tests, but some IDEs, such as PHPStorm, can provide it to you.

I hope this link can help you:

https://confluence.jetbrains.com/display/PhpStorm/Creating+PHPUnit+Tests+in+PhpStorm

0
source

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


All Articles