繁体   English   中英

Laravel:PHPUnit测试不会触发

[英]Laravel: PHPUnit tests not triggering

我想测试我的一门课,但看来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$

谢谢你的帮助!

请不要使用__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');
    }

}

暂无
暂无

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

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