当前位置:Gxlcms > PHP教程 > Yii2codeceptunit类找不到

Yii2codeceptunit类找不到

时间:2021-07-01 10:21:17 帮助过:23人阅读

我的测试代码如下

 1,
            'channel_id' => 2,
        ];
        $this->assertTrue(UserSource::recordUserReg($params));



    }
}

执行的时候会抱如下错误:

Unit Tests (1) --------------------------------------------------------------------------
E UserSourceUintTest: Me 
-----------------------------------------------------------------------------------------


Time: 40 ms, Memory: 6.00MB

There was 1 error:

---------
1) UserSourceUintTest: Me
 Test  tests/unit/UserSourceUintTest.php:testMe
                                                   
  [Error] Class 'app\models\UserSource' not found  
                                                   
#1  UserSourceUintTest->testMe

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

下代码为我参照官方的

Classical Unit Testing
Unit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:

username = null;
        $this->assertFalse($user->validate(['username']));

        $user->username = 'toolooooongnaaaaaaameeee';
        $this->assertFalse($user->validate(['username']));

        $user->username = 'davert';
        $this->assertTrue($user->validate(['username']));           
    }
}

我的问题到底出在哪里?谢谢各位不吝赐教。

回复内容:

我的测试代码如下

 1,
            'channel_id' => 2,
        ];
        $this->assertTrue(UserSource::recordUserReg($params));



    }
}

执行的时候会抱如下错误:

Unit Tests (1) --------------------------------------------------------------------------
E UserSourceUintTest: Me 
-----------------------------------------------------------------------------------------


Time: 40 ms, Memory: 6.00MB

There was 1 error:

---------
1) UserSourceUintTest: Me
 Test  tests/unit/UserSourceUintTest.php:testMe
                                                   
  [Error] Class 'app\models\UserSource' not found  
                                                   
#1  UserSourceUintTest->testMe

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

下代码为我参照官方的

Classical Unit Testing
Unit tests in Codeception are written in absolutely the same way as it is done in PHPUnit:

username = null;
        $this->assertFalse($user->validate(['username']));

        $user->username = 'toolooooongnaaaaaaameeee';
        $this->assertFalse($user->validate(['username']));

        $user->username = 'davert';
        $this->assertTrue($user->validate(['username']));           
    }
}

我的问题到底出在哪里?谢谢各位不吝赐教。

人气教程排行