首页 > Web开发 > 详细

php单元测试/涉及代码覆盖率——netbeans工具

时间:2015-03-27 16:32:05      阅读:443      评论:0      收藏:0      [点我收藏+]

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右键,选中“运行”,查看测试结果
技术分享

php单元测试/涉及代码覆盖率——netbeans工具

原文:http://www.cnblogs.com/nimezi/p/4371577.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!