Test tool to invoke action under thinkphp environment

Source: Internet
Author: User

0. Preface

> I developed a tool to help thinkphp developers simulate front-end AJAX requests to improve test efficiency.

Front and back-end developer Division of labor is a common way to develop Web projects. In the case of inconsistent development progress, back-end developers often face the embarrassment of not being able to validate the program through the front-end interface, which often can only be tested in the form of mock requests, which can be more cumbersome to simulate in a thinkphp environment. Based on the accumulation of past projects, I developed a test tool to help developers simulate HTTP requests to invoke the backend Action Service. This article describes the tool's functionality and how to get it, how it is used, and some key points in the implementation process.

1. function

Based on the goal of improving test efficiency, some useful features are added.

This test tool mainly includes the following features:

    • The AJAX request backend service is simulated on the required path, of course, the normal HTTP request is also possible;
    • Of course, parameters can be submitted;
    • Of course, you can show the results of the AJAX request returned, in JSON, trying to format the JSON nicely;
    • The test path can be generated automatically according to the characteristics of thinkphp;
    • You can save the input test parameters without repeating the input, this feature may be more useful, of course, there must be database support.
2. Deployment

The test tool itself is an application developed based on thinkphp and relies on thinkphp deployment.

    • Download

Click here to download the tool: http://download.csdn.net/detail/zhongping136/8518139.

    • Deploying Apps

Download the compressed package to the directory where thinkphp is located, that is, in the same directory as the index.php. The test.php in the compressed package is the entry file for the test app. An understanding of the entry document can be found in the Official Thinkphp Handbook. If you do not like the file name test.php, you can change the name, but you need to modify the Test_entrance entry in the configuration file.

    • Database initialization

In the download of the compressed package has Test.sql, please select the appropriate database execution, create a data table. The Script default table is prefixed with "tptest_" and can be modified as needed.
After creating the table, modify the database-related options in the configuration file in the Test app: database, user, password, and more, see Configuration file (/test/common/conf/config.php). If you modify the table prefix when you create the data table, be aware of configuring the Db_prefix option.

    • Complete

Access to http://webroot/test.php, if the Web server configuration is not a problem, you can see the test application interface.

3. Use

Describes key inputs, buttons, and possible pits, for example a normal process.

    • Input items

Entry file: Default fill index.php, if not modify the default index.php, this entry will not be ignored.
Module: thinkphp the application into a module, where the module name, such as home, is required.
Test action: Here is a pit, fill in the format must be "controller/action", such as "Index/index".
Path: According to the operation of the thinkphp specification access path, you can fill in, of course, you can click the "Generate Path" button to automatically generate the required path.
Parameters: Parameters that need to be submitted, including parameter names and value two items. You can add multiple parameters (click "Add Parameter"), and the unwanted parameters can be removed (click "X").
Parameter merge result: can be filled in by "Act=testu&arg=value", also can click "Merge parameter" to merge automatically.
Save test data: By default, the data is automatically saved before testing (automatic data filtering), and if unchecked, the input results of the above options will not be saved.
Ajax submission: By default the data is submitted in Ajax (POST), if unchecked, the full URL is organized in thinkphp URL mode and the action is accessed in the new page.

    • Button

Select action: Select the saved test data in the dialog box and click on the action list to automatically fill in the entries.
Generate Path: Action All options must be entered after input to generate the most recent URL path.
Submit test: After the path is generated, enter the required parameters, click this button to submit the test, output the returned AJAX results to the interface, or access the test path in the new page (non-Ajax mode).

    • Operation Flow

Entry file fill in test.php, module Home, test action fill index/qrypath; Click Generate path, the path input box is assigned value/test.php/home/index/ qrypath.html, parameter value Testu, click on merge parameter, parameter merge result is assigned, click Submit Test, return result in background is displayed in execution result.

4. Realize

It may be useful to have such a tool, but you can do it better, right, so talk.

    • Jquery

The front end, of course, is inseparable from great Jquery,ajax requests, DOM access, dynamic addition of deleted elements, and jquery easier.

    • Jmpopups

Jquery.jmpopus, A Concise jquery popup dialog box plugin. Only 0.5.1, no subsequent update is found, the example uses jquery1.3.2, the latest version of jquery has compatibility issues, and lazy use a compatible version of 1.3.2.

    • Jsbt

In order to make the JSON object look good, using the jstb.js, this is a tool for formatting code, a bit overqualified.

    • Generating paths

The U method provided by thinkphp can generate the access path according to the controller's specific operation, such as U (' home/user/add ') to generate the add operation address of the User module of the Home group, but in the test application, the portal file is test.php, and the resulting path is also/ test.php/home/user/add.html; The actual entry file is index.php, you need to replace test.php with index.php.

    • App Packaging

When the tool is published, JS files and PHP code together packaged together, to see my other blog "thinkphp Environment JS file by module Deployment" may be helpful, website:
http://blog.csdn.net/zhongping136/article/details/44172229

5. Summary

Take the time to do a test tool, the development process can provide back-end developers a test on the Traverse, a brief introduction of the tool's function and application methods, examples of the implementation of the use of the third-party code and considerations, you can directly use this tool, you can also develop a more complete tool out.

Original blog, reproduced please specify the source: http://blog.csdn.net/zhongping136, thank you!

Test tool to invoke action under thinkphp environment

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.