Learning the essence of PHP and writing efficient PHP code for Automatic Testing

Source: Internet
Author: User

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 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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.