简体   繁体   English

CakePHP应用程序中的单元测试脚本

[英]Unit-testing scripts in CakePHP application

I have developed a deal application using CakePHP. 我已经使用CakePHP开发了一个交易应用程序。 Now I want to write the unit-scripts using PHPUnit. 现在,我想使用PHPUnit编写单元脚本。 I have installed PHPUnit on my server and test core tests is working fine. 我已经在服务器上安装了PHPUnit,并且测试核心测试工作正常。 Installed Xdebug also for code analyze. 还安装了Xdebug,用于代码分析。 When I am going to scripts for existing application then it is not working. 当我要为现有应用程序编写脚本时,它将无法正常工作。 I am able to write the unit-script for login menthod in model. 我能够在模型中编写登录方法的单元脚本。 But can't write the scripts for remaining methods. 但是不能为其余方法编写脚本。

<?php

App::uses('User', 'Model');

class UserTest extends CakeTestCase {
    public $fixtures = array('app.user');
    public $dropTables = false;
    public function setUp() {
        parent::setUp();
        $this->User = ClassRegistry::init('User');
    }

    public function testLogin() {
         $result = $this->User->find('count', array(
            'conditions' => array(
                // making some assumptions about the test data here
                'email' => 'test.user@gmail.com',
                'password' => 'f1054da373ace628dc73b8ec52eb28072b074940',
            ),));
        $expected = 1;
        $this->assertEquals($expected, $result);
    }

}
?>

it is working well. 运行良好。 But I am not able to write scripts for the remaining methods. 但是我无法为其余方法编写脚本。

Try using bake and bake the tests to get started with the correct testing structure: 尝试使用烘焙和烘焙测试以开始使用正确的测试结构:

cake bake test

This might help push you in the write direction with the way Cake expects the test to be structured. 这可能会帮助您以Cake期望测试结构化的方式将您推向写入方向。 It will also create the empty methods to test all of the methods in the controller. 它还将创建空方法来测试控制器中的所有方法。

Can you be more specific about what is not working? 您能更详细地说明哪些无效吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM