We are using these for testing class methods. These tests are assigning different inputs to methods and testing if they get correct output. Example is validator of phone numbers, which we can use in different apps. Unit test can test for example 20 different phone nubmers if they are valid or no.
Acceptance/blackbox tests
Usually test some functionality, for example for article writing we need to test different use cases (write article, approve article, deny article, publish article…) These test usually use Selenium framework, which can simulate real use by clicking in browser.
Integration tests
If we have complex app which is using different services, integration tests are testing if everything fit together.
System tests
Used for example in live environment, where app must handle thousands of users.
Unit tests - Example
We will create simple calculator and we will use Codeception framework, which includes PHPUnit, acceptance wrapper for Selenium and other frameworks.
In your project folder:
Download codecept.phar from http://codeception.com/quickstart
Now run php codecept.phar bootstrap. That should generate tests folder for you. Under tests\unit create tile _bootstrap.php which will load all classes which will be tested.
Also you need to add settings: bootstrap: _bootstrap.php to codeception.yml.
So your project folder should look like this:
To generate unit tests run php codecept.phar generate:test unit Kalkulacka. This will create following file under tests/unit:
We need to update this file for testing:
assertEquals() parameters:
1 - expected value
2 - actual value
3 - error message
4 - result tolerance
Using @expectedException InvalidArgumentException in testDeleniVyjimka is testing if really happens exception with zero.
Run test with php codecept.phar run unit. You should see something like: