【问题标题】:Laravel: PHPUnit tests not triggeringLaravel:PHPUnit 测试未触发
【发布时间】:2015-01-20 22:04:01
【问题描述】:

我想测试我的一门课程,但看起来Phpunit 不起作用。

这是下面的测试:

<?php

use NERO\Datagrids\Datagrid;

class DatagridTest extends TestCase
{

    public function __construct()
    {
        $this->datagrid = new Datagrid;
    }

    public function testStopMethod()
    {
        $response = $this->datagrid->stop();
        $this->assertEquals($response, 'Stop');
    }

}

还有课程本身:

<?php

namespace NERO\Datagrids;

class Datagrid {

    public function stop()
    {
        return 'Stop';
    }

}

我没有从命令行得到任何响应。我执行以下操作,但没有任何反应..

intelis:laravel me$ clear
intelis:laravel me$ vendor/bin/phpunit 
intelis:laravel me$

感谢您的帮助!

【问题讨论】:

    标签: php unit-testing laravel laravel-4 phpunit


    【解决方案1】:

    请不要使用__construct,而是:

    <?php
    
    use NERO\Datagrids\Datagrid;
    
    class DatagridTest extends TestCase
    {
        protected $datagrid;
    
        public function setUp()
        {
            $this->datagrid = new Datagrid;
        }
    
        public function testStopMethod()
        {
            $response = $this->datagrid->stop();
            $this->assertEquals($response, 'Stop');
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 1970-01-01
      • 2021-07-06
      • 2019-06-18
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      相关资源
      最近更新 更多