Learn the essence of PHP and write efficient PHP code for automatic testing. If you want to make a perfect product, you must perform comprehensive inspection and testing on it. There are several types of tests, each of which targets a specific aspect of the application. This article will conduct a comprehensive inspection and test on perfect products to be manufactured. There are several types of tests, each of which targets a specific aspect of the application.
This article describes unit testing, database testing, system testing, and load testing.
I. Unit testing
Unit testing is a step-by-step test of an application. make sure that all components work properly. Without a unit test, it is generally quite difficult to find out the cause of the incorrect running in the application.
A unit test usually uses a unit test framework, which provides the basic structure required to write and run the test and output the result.
Some commonly used unit test frameworks include:
PHPUnit: http://phpunit.de/
SimpleTest: http://www.simpletest.org/
PHPT: http://qa.php.net/write-test.php
2. database testing
PHPUnit database extension imitates the DbUnit extension of JUnit, which is a de facto Java unit test framework. PHPUnit database extensions do not process the creation of databases, tables, or user creden。; they run on the assumption that these have been created.
PHPUnit database test reference: http://phpunit.de/manual/current/en/database.html
III. system testing
Once the components of the system and the interaction with the external system have been tested, we will test the application as a whole, which becomes a system test.
For Web applications, this is often done by writing automated tests in the same way that a real user will use to interact with the browser.
The popular software package for writing and executing such tests is Selenium, which is a Java-based server. it runs a client to connect to it and runs commands to start and interact with the browser. This software is often used to execute a series of actions within a Web application and assert the last loaded file content to confirm that it achieves the expected functionality.
Selenium: http://seleniumhq.org/
PHPUnit contains a Selenium extension that allows these interactions to be executed.
IV. Load Testing
Once an application works properly, it is essential to understand how the application runs as a whole, regardless of its components or as a whole.
The load test simulates the behavior of a group of users to determine how the application performs under the load.
Next, we will introduce two testing tools: AB and siege.
1. AB testing tool
As part of the Apache HTTP Server Project, AB is a relatively simple benchmark testing tool developed and applicable to most environments where Apache is installed.
It has many parameters, and we have a slight adjustment to how to guide the test. Three of them are frequently used:
1)-c #: the number of concurrent requests per second or the number of users simultaneously accessing the application.
2)-n #: The request to be sent.
3)-t #: the maximum duration of the test duration in seconds. this is assumed to be-n 50000.
For example, if you want to simulate the behavior of 10 concurrent users in one minute, you can use the following command:
ab -c 10 -t 60 http://localhost/phpinfo.php
AB reference: http://httpd.apache.org/docs/2.0/programs/ AB .html
2. Siege testing tool
Another common load testing tool is Siege, which is developed by Joe Dog. The load test of AB is restricted to a specific URL. in addition to the URL, Siege can also perform load tests on the entire application. The Siege manual describes the options it supports.
Siege: http://www.joedog.org/siege-home/
Siege manual: http://www.joedog.org/siege-manual/
Bytes. There are several types of tests, each of which targets a specific aspect of the application. This article will...