博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php单元测试/涉及代码覆盖率——netbeans工具
阅读量:4673 次
发布时间:2019-06-09

本文共 2556 字,大约阅读时间需要 8 分钟。

1.入门

https://netbeans.org/kb/trails/php_zh_CN.html

NetBeans是开源软件开发集成环境,是一个开放框架,可扩展的开发平台,可以用于Java、C/C++,PHP等语言的开发,本身是一个开发平台,可以通过扩展插件来扩展功能。

 

2.搭环境

软件,插件等参照 文件中的NetBeans.rar

前提:wamp server环境OK

准备谷歌自由版(netbeans插件ok)

a.首先必须先安装jdk-8u40-nb-8_0_2-windows-x64.exe

b.安装netbeans-8.0.2-windows.exe

c.将以下3个插件放在wamp\bin\php\php5.5.12 目录中

更新wamp\bin\php\php5.5.12\zend_ext\php_xdebug的dll文件版本

d.设置电脑环境变量

e.安装pear(规范你的代码,并便于日后快速生成文档)
在管理员权限下运行,运行后,会生成对应文件及文件夹
D:\wamp\bin\php\php5.5.12\php.ini
中自动插入path路径
 
f.追加pear环境变量
 
g.修改2个文件夹中的php.ini文件
1)wamp\bin\php\php5.5.12\php.ini
可以变动下pear文件的存放位置
 
修改php_xdebug文件名字
 
 
添加以下内容
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.auto_trace=1
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.trace_output_dir="d:/wamp/xdebug/trace"
xdebug.profiler_enable=1
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir="d:/wamp/xdebug/profiler"
 
2)wamp\bin\apache\apache2.4.9\bin\php.ini
同样
 
3.启动wampserver的服务
打开netbeans软件
文件-新建项目
下一步
下一步
完成
 
工具-选项-常规
web浏览器-编辑
添加新的浏览器,使用文件夹中的谷歌自由版,里面有netbeans相关插件
 
选项-PHP-常规
添加解析器
框架和工具
选择phpunit,添加phpunit脚本和框架生成器脚本
 
4.创建完项目后,修改属性-测试,phpunit打勾
 
5.选中某个源文件中的需要测试的php文件,单击右键“工具”-“创建测试”,输入测试文件存放目录
生成xxxtest.php文件,修改代码,执行测试任务
 
 6.举例
源文件test.php
----------------------------------------
<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of Sample
 *
 * @author sicnco
 */
class Sample {
    //put your code here
    public function Get($a)
    {
        if($a==1)
        {
            return 'ok:'.$a;
        }
        else
        {
            return 'ng:'.$a;
        }
    }
}
 --------------------------------------
修改后的测试文件testtest.php
<?php
require_once '../test.php'; 
<------这一行需要手动添加
/**
 * Generated by PHPUnit_SkeletonGenerator on 2015-03-27 at 03:50:41.
 */
class SampleTest extends PHPUnit_Framework_TestCase {
    /**
     * @var Sample
     */
    protected $object;
    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp() {
        $this->object = new Sample;
    }
    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown() {
        
    }
    /**
     * @covers Sample::Get
     * @todo   Implement testGet().
     */
    public function testGet() {
        $rlt = $this->object->Get(1);              
<----需要写代码,验证
        $this->assertEquals($rlt, 'ok:1');         
<----验证代码运行结果
    }
}
 
 
点击测试文件testtest.php右键,选中“运行”,查看测试结果

转载于:https://www.cnblogs.com/nimezi/p/4371577.html

你可能感兴趣的文章
UWP 播放声音文件
查看>>
大学毕业后拉开差距的真正原因
查看>>
记一次成功部署kolla-ansible ocata版本过程
查看>>
hdu3507 Print Article
查看>>
Vue 组件 data为什么是函数
查看>>
Java反序列化漏洞通用利用分析
查看>>
一次面试留下的实际应用问题。关于HttpModule,IIS集成模式。
查看>>
Centos系统创建用户oracle后,用该用户登陆系统,页面加载报错GConf error
查看>>
SQL的注入式攻击方式和避免方法
查看>>
删除串中指定的字符
查看>>
http协议详解
查看>>
curl http_code状态码 含义
查看>>
学习HTML(1)
查看>>
重写equals方法(未完)
查看>>
2.2.2python的BeautifulSoup库
查看>>
PostgreSql之在group by查询下拼接列字符串
查看>>
MariaDB Centos7 下安装MariaDB
查看>>
Git
查看>>
中文词频统计
查看>>
idea部署web项目到tomcat注意事项
查看>>