开发者

Generate tests for all the classes from a directory

I have a directoy structure, and all the classes of the business logic are placed in the app_dir/lib/ directory. I would like to generate unit tests for all the classes from this lib/ folder.

The problem is, that I haven't found any option to specify the source directory, only the source file:

from app_dir:

$ phpunit --skeleton-class lib/
Error: "lib/.php" could not be opened.

Is it the only solution to write my own php script, which iterates through the /lib folder and calls the skeleton generator for every file found? And how can I specify the output folder, where all the generated t开发者_如何学JAVAest files are placed?


To generate skeleton tests, you want --skeleton-test not --skeleton-class. This will extract the filename without the extension and pass it to phpunit.

for file in *.php; do phpunit --skeleton-test "${file%.*}"; done;

I have no idea how to change the output directory which you would need if you want to run the command multiple times. I suppose a better one-liner would only select files not ending with "Test.php".


From Sebastian Bergmann's blog:

As of changeset 2764, PHPUnit 3.3's command-line test runner accepts a directory as its argument.

Given a directory, the test runner will recursively scan the directory for *Test.php files, build a test suite out of the *Test classes, and run it.

With PHPUnit >= 3.3 you should be able to execute just:

phpunit lib
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜