This are the steps for complete implemention of unit testing in Laravel:
1. In the composer.json include the lines in require array:
"phpunit/phpunit": "4.0.*"
2.In the composer.json add this lines also in the autoload array as without this it would not work:
"app/tests/"
3.Most important task is to add envirornment variable unless it would phpunit command would not work. To do add the lines:
To get phpunit working I edited the 'Path' environment variable.
Method for windows 7
1) Right click on 'My computer'->properties
2) In the left hand column click 'Advanced System Settings'
3) under the Advance tab click 'Enviroment Variables'
4) Under 'System Variable' local the 'Path' variable and click edit
5) Append the location of phpunit.bat to the end of the variable data. IE C:/some/other/thing; C:/something/else; C:/myproject/laravel/vendor/bin/
6) Save it all.
4.Now run the command to run the test case:
php vendor/phpunit/phpunit/phpunit
5. Create a test case file in the tests folder eg AddTest.php . This is sample code:
<?php
/*
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class AddTest extends TestCase
{
public function testAddYearsPositive()
{
$this->assertSame(1976, 1976);
}
public function testAddYearsZero()
{
$this->assertSame(1975, 1975);
}
}
6. Run the command:
php vendor/phpunit/phpunit/phpunit
and you will get the output:
PHPUnit 4.0.20 by Sebastian Bergmann.
Configuration read from C:\server\www\elms\phpunit.xml
...
Time: 445 ms, Memory: 10.50Mb
[30;42mOK (3 tests, 3 assertions) [0m
7. This will also fix the issue:
'phpunit' is not recognized as an internal or external command,
operable program or batch file.
Kindly contact if any issue .
Thanks
1. In the composer.json include the lines in require array:
"phpunit/phpunit": "4.0.*"
2.In the composer.json add this lines also in the autoload array as without this it would not work:
"app/tests/"
3.Most important task is to add envirornment variable unless it would phpunit command would not work. To do add the lines:
To get phpunit working I edited the 'Path' environment variable.
Method for windows 7
1) Right click on 'My computer'->properties
2) In the left hand column click 'Advanced System Settings'
3) under the Advance tab click 'Enviroment Variables'
4) Under 'System Variable' local the 'Path' variable and click edit
5) Append the location of phpunit.bat to the end of the variable data. IE C:/some/other/thing; C:/something/else; C:/myproject/laravel/vendor/bin/
6) Save it all.
4.Now run the command to run the test case:
php vendor/phpunit/phpunit/phpunit
5. Create a test case file in the tests folder eg AddTest.php . This is sample code:
<?php
/*
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class AddTest extends TestCase
{
public function testAddYearsPositive()
{
$this->assertSame(1976, 1976);
}
public function testAddYearsZero()
{
$this->assertSame(1975, 1975);
}
}
6. Run the command:
php vendor/phpunit/phpunit/phpunit
and you will get the output:
PHPUnit 4.0.20 by Sebastian Bergmann.
Configuration read from C:\server\www\elms\phpunit.xml
...
Time: 445 ms, Memory: 10.50Mb
[30;42mOK (3 tests, 3 assertions) [0m
7. This will also fix the issue:
'phpunit' is not recognized as an internal or external command,
operable program or batch file.
Kindly contact if any issue .
Thanks
Comments
Post a Comment