问题
What possibilities are there to run unit tests with my Yii application?
So far, I have been testing them this way:
Open command prompt
> cd C:\WHEREVER MY APP IS\protected\tests
> phpunit unit/TestingTest.php
Now, I was wondering if there is another way. Im new to the testing world so to speak, but it seems to me that there must be a better way than running one by one all tests. Thanks for any tips, im sure the question is quite dumb! But maybe it turns out to be helpful to someone else out there.
EDIT (based on @David Harkness comment) Ok, so now I know that when i do this
phpunit C:\WHEREVER MY APP IS\protected\tests\unit
All the tests within my TestingTest.php file are execute. My problem now is that within that unit folder, I have TWO files, TestingTest.php and TestingTest2.php Testing2Test.php. Only the tests within the first one are executed. Any ideas?
回答1:
PHPUnit by default will scan for all files named <foo>Test.php
. That means that TestingTest2.php
will be ignored. You can either rename the file to Testing2Test.php
, use
phpunit C:\WHEREVER MY APP IS\protected\tests\unit\*.php
to locate the files (not sure this works though), or create a phpunit.xml configuration file that specifies the filename pattern that must match your tests. However, just rename it so all the files end in Test.php
and you'll be much happier.
I generally always cd
into the root test directory--the one that contains bootstrap.php
and phpunit.xml
. That way I don't have to tell PHPUnit how to find those files since it always looks in the current directory.
来源:https://stackoverflow.com/questions/7922766/running-phpunit-tests-yii-framework