PHP - Getting Started PHPUnit test with simple exampleBy Hardik Savani | February 12, 2017 | | 3185 Viewer | Category : PHP
PHPUnit is a one type of unit testing framework for PHP language. In todays PHPUnit is very popular for testing. Most of site owner want to implement PHPUnit test because that way we can simply test using command. Without testing our website will never be good to publish. But if you don't know about PHPUnit and no idea how to start so just follow bellow example for scratch.
I will give you very simple example of PHPUnit and how it works from scratch. I make quick easy example with phpunit command. We have to create two file like as listed bellow:
Before start example make sure you have installed PHP. So you have to just follow bellow files to complete example.
php phpunit.phar --version
Create MyTest.php File
public function add($a, $b)
return $a + $b;
Create MyTestTests.php File
class MyTestTests extends TestCase
protected function setUp()
$this->mytest = new MyTest();
protected function tearDown()
$this->mytest = NULL;
public function testAdd()
$result = $this->mytest->add(1, 3);
Now we are ready to run bellow simple example by following example:
php phpunit.phar MyTestTests.php
You will be find this way result:
I hope it can help you...
- How to redirect route with querystring in Laravel 5?
- How to send mail example in Laravel 5?
- Laravel 5 - "syntax error or access violation 1055 in group by" Solved
- How to send mail using mailable in laravel 5.3?
- How to check current password using hash check in Laravel 5.3?
- How to send mail using Sendgrid in laravel 5?
- Laravel 5 - multiple files download with response example
- laravel 5.4 New Feature - Add eloquent whereKey method