Assume we have 500 unit tests and running all of them by:
php ./vendor/bin/phpunit -c ./phpunit.xml
and 450 tests passed but failed at unit-test 451.
Now I fixed the uni-test 451 and don't want to re-run 450 tests again and just want to continue testing from 451 to the the end.
Any ideas would be appreciated
Related
I have recently upgraded to PHPUnit 9.5.20 and noticed that it is printing #StandWithUkraine for every test run. Eg.
Testing started at 10:01 am ...
Running in local mode
PHPUnit 9.5.20 #StandWithUkraine
Time: 00:01.141, Memory: 24.00 MB
OK (1 test, 4 assertions)
I guess you would have to edit actual source code of the package, and that seems not recommended.
But the banner is located in phpunit / src / TextUI / TestRunner.php on line 322 - 331
I guess removing it would do the trick, however I haven't tried it and don't recommend.
The banner is also mentioned in a few other files. I've tracked down a commit made by the package author so you can see where the banner is mentioned.
Commit by author
I have a large number of tests in a PHP Unit test suite.
All tests will pass when running the complete suite, however when run individually, certain tests may pass or fail depending on how I call PHP Unit:
$ php phpunit --configuration phpunit.xml --filter FooIntegrationTest
PHPUnit 5.7.19 by Sebastian Bergmann and contributors.
................ 16 / 16 (100%)
Time: 3.97 seconds, Memory: 109.50MB
OK (16 tests, 36 assertions)
vs.
$ php phpunit --configuration phpunit.xml tests/Integration/FooIntegrationTest.php
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
..........F.F... 16 / 16 (100%)
Time: 3.73 seconds, Memory: 111.75MB
FAILURES!
Tests: 16, Assertions: 36, Failures: 2.
The failures in question are unexpected results (i.e. the code runs just fine), no PHP errors or Exceptions.
The majority of tests will pass both ways, and there doesn't seem to be anything special about those tests that produce the above results.
Solved.... namespace conflict from an unrelated test class
phpunit ... FooIntegrationTest.php only opens & runs the single class file specfied
whereas phpunit ... --filter FooIntegrationTest will open every file in the suite to look for matching tests; which lead to a globally namespaced function in another file causing false pass.
Lesson learned: don't declare globally namespaced functions in unit test classes!
I am using the cakephp test (php unit test) with xdebug to run the server side code and monitor the output from the terminal rather than using it for validation.
So, every time, i want to run some particular lib/controller/model method from the terminal and see the output, i have to comment out the other test case functions.
I know this might not be the right approach,
but i want to know, if there is a way, i can build up a wrapper around the cake test, that will take the argument of the method name which i want to run?
There is no need to write a wrapper script
To run one test method
Use the filter option:
-> phpunit --help
PHPUnit 4.4.1 by Sebastian Bergmann.
Usage: phpunit [options] UnitTest [UnitTest.php]
phpunit [options] <directory>
...
Test Selection Options:
--filter <pattern> Filter which tests to run.
For example:
-> phpunit --debug --filter testValidationDefault tests/TestCase/Model/Table/PostsTableTest.php
PHPUnit 4.4.1 by Sebastian Bergmann.
Configuration read from /var/www/cakephp.dev/phpunit.xml.dist
Starting test 'App\Test\TestCase\Model\Table\PostsTableTest::testValidationDefault'.
I
Time: 130 ms, Memory: 9.75Mb
OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Incomplete: 1.
www-data # dev [ /var/www/cakephp.dev ]
->
To run only one test use the filter option in the cake command line tool:
cake test app Model/Post --filter testGetAllPostsByAuthor
Works on CakePhp 2.2
Hi i am quit new in Laravel PHPUnit, getting the following error :
Laravel : phpunit cannot open file ExampleTest.php
I don't have idea why i am getting this error. I installed PHPUnit globally and when i run "phpunit" in terminal it runs fine. But I want to run it on specific file like :
phpunit ExampleTest
Thanks In Advance.
Make sure you are on the project root and referencing the file inside the tests folder.
Example:
phpunit tests/ExampleTest.php
I am working in Windows. Try to use the full path:
C:\Desktop\code\blog\vendor\bin>phpunit C:\Desktop\code\blog\tests\Feature\ExampleTest.php
PHPUnit 7.2.6 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 1.46 seconds, Memory: 10.00MB
OK (1 test, 1 assertion)
This started happening when I upgrade phpUnit, I had to update phpStorm to fix it.
try it like this:
vendor\bin\phpunit tests\Unit\ExampleTest.php
it will work surly
but first install phpunit globally.
Maybe you call wrong to your test.
Try like this :
php artisan test --filter YourTestClassName
When I run PHPUnit on the command line it works fine:
$ phpunit --bootstrap Tests/autoload.php Tests/Classes/Database/customer/CreativeTest
PHPUnit 4.1.4 by Sebastian Bergmann.
...
Time: 225 ms, Memory: 12.50Mb
OK (3 tests, 34 assertions)
However when I try to run it with Jenkins the bootstrap autoload is apparently failing because it says it can't find the parent class of CreativeTest:
[workspace] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson3966267216183299087.sh
+ /usr/local/bin/phpunit --bootstrap Tests/autoload.php Tests/Classes/Database/customer/CreativeTest
PHP Fatal error: Class 'LPtools\Tests\LPTest' not found in /Users/Shared/Jenkins/Home/jobs/LPtools_Unit_Tests/workspace/Tests/Classes/Database/customer/CreativeTest.php on line 20
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I'm a Jenkins novice so any help here would be awesome!