Detailed explanation of interface automation steps in phpunit

php中世界最好的语言
Release: 2023-03-26 12:04:01
Original
1528 people have browsed it

This time I will bring you a detailed explanation of the steps for phpunit to implement interface automation. What are theprecautions for phpunit to implement interface automation?. Here are actual cases, let’s take a look.

I came into contact with phpunit by chance at the beginning of the year, an open source software developed with PHPprogramming language, and also aunit testingframework. If used effectively, the interface can be greatly improved. Traversal efficiency. Not much nonsense, let’s get straight to the point.

1.Install

In the directory of php

pear channel-discover pear; pear install phpunit/PHPUnit
Copy after login

2.Configuration

First create aconfiguration file stored in the lib folder, then create a new transfer.php file


        
Copy after login

Finally create a basetest.php file


        
Copy after login

The interface test environment is now set up.

3. Write test cases

assertEquals($obj['retval'], $expect); return $obj; } private function call_https($path, $param, $expect = 'ok') { $_param = build_get_param($param); $url = HTTPSPREFIX . "$path?" . $_param; $buf = do_Get($url); $obj = json_decode($buf, True); $this->assertEquals($obj['retval'], $expect); return $obj; } public function testLogin(){ $param = array( 'type' => 'phone' ,'token' => PHONE ,'password' => PWD ); $url = 'login'; return $this->call_http($url, $param); } /** * @depends testLogin */ public function testInfo(array $user){ $session = $user['retinfo']['session']; $param = array( 'session' => $session ); $url ='info'; return $this->call_http($url, $param); }
Copy after login

If it is a post request

public function testPost(){ $session = $user['retinfo']['sessionid']; $param = array( ,'data' => '111' ); $url = POSTURL.'posturl'; return do_POST($url,$param); }
Copy after login

I believe you have read it You have mastered the method in the case of this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of user information query, update and delete steps in the ThinkPHP framework

ThinkPHP connection database operation case analysis

The above is the detailed content of Detailed explanation of interface automation steps in phpunit. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!