Table of Contents
回复内容:
Home Backend Development PHP Tutorial PHP测试很有必要,大家都是如何做的呢?

PHP测试很有必要,大家都是如何做的呢?

Jun 06, 2016 pm 08:46 PM
php test

如题 ~~PHP测试很有必要,大家都是如何做的呢?
怎么规范自己的测试及其测试应注意什么?

回复内容:

如题 ~~PHP测试很有必要,大家都是如何做的呢?
怎么规范自己的测试及其测试应注意什么?

主要还是看框架是如何指导测试的。

codeigniter 用自己的写的类库进行简单的断言测试,测试结果直接输出到页面或者保存到文件。比较原始手工化。

Yii framework 用PHPUnit作为测试类库,另外还用了Selenium来模拟正式操作场景测试具体浏览器下面的操作结果。(Selenium的使用是比较虐心的一件事,相当于用代码模拟用户在浏览器上的每个操作后断言预期的结果)

Laravel 同样是采用PHPUnit作为测试类库,以测试后面业务逻辑为主,但是在针对前端的测试上主要是针对生成的Html页面的内容来进行一些简单的断言。

我知道测试类库除了PHPUnit之外还有SimpleTest,不过没有使用与了解过。

代码测试覆盖率达到80%左右应该也就差不多了,没有追求100%的必要。毕竟,需求是动态的。

单元测试能做,首先依赖于编写的代码,写的随意的代码,是很难做单测的,所以,第一项工作就是要编写可以测试的代码,所以开发的时候就要考虑怎么测试,如果能遵循测试驱动开发,敲码前先写单测,那更好;

第二项工作,就是单测的编写了。往往打桩是比较麻烦的,但是越大的系统,依赖的外部组件和系统越多,不打桩根本无法测试。目前phpunit有支持打桩。

第三,如果是旧项目,代码写的随意,缺少封装,过程式的,甚至是面包屑代码,如何测试?我能想到的,要么重构代码,要么就得做大量的打桩工作;即使如此,也不能保证真的就能对这些代码进行单测。

以前我用thinkphp写程序,然后想做一下单元测试,然后就没有然后了。

一般基本的流程走一遍,测试下。一般的框架都有调试模式,开启了多调试调试~

在工作不忙的时候,是单元测试和restTest一起做的。忙的时候就做restTest就行了。
但愿测试就不细说了。
restTest就是用php写一个和项目中联系紧密的rest客户端,然后用php自带的httpServer做服务器启动项目(注意选择测试库),然后用unittest跑脚本一个个的访问rest接口。判断错误等等。

单元测试,PHPUnit

做一个hook 然后手写测试代码然后看结果

很少去做测试,一般情况都是编译下,没有问题就可以了。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles