Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel:具有单击功能的单元测试_Laravel_Unit Testing_Testing - Fatal编程技术网

Laravel:具有单击功能的单元测试

Laravel:具有单击功能的单元测试,laravel,unit-testing,testing,Laravel,Unit Testing,Testing,我正在使用laravel5.6,目前正在编写测试 我希望在单元/功能测试中执行类似的操作 $this->actingAs( $user)->visit('/') ->click('my_button'); 但在默认测试中,单击/访问功能不可用。它们仅在使用Dusk 但是dash运行需要更多的时间,是否可以在phpunit运行的默认单元测试中恢复一些功能,如单击 我看到这是“带回”thoses函数,但它是必要的吗?或者我应该简单地用

我正在使用laravel
5.6
,目前正在编写测试

我希望在单元/功能测试中执行类似的操作

$this->actingAs( $user)->visit('/')
                       ->click('my_button');
但在默认测试中,单击/访问功能不可用。它们仅在使用
Dusk

但是
dash
运行需要更多的时间,是否可以在
phpunit
运行的默认单元测试中恢复一些功能,如
单击


我看到这是“带回”thoses函数,但它是必要的吗?或者我应该简单地用
dash
运行它以避免进一步的问题吗?

PHPUnit应该是随Laravel开箱即用的

您只是运行它们与使用黄昏时不同

php artisan make:test UserTest
使用此选项创建新测试,然后使用以下选项:

class ExampleTest extends TestCase
{
/**
 * A basic functional test example.
 *
 * @return void
 */
public function testBasicExample()
{
    $this->actingAs( $user)->visit('/')
                   ->click('my_button');
}
} 

另外,请检查项目中是否有phpunit.xml设置。

我这样做了,但是当我运行测试时,phpunit告诉我
错误:调用未定义的方法Tests\Feature\ExampleTest::visit()
刚刚记住的5.4或更高版本中没有visit函数。如果要使用旧功能,可以安装浏览器套件。composer需要laravel/浏览器套件测试Yep。这就是我发布这个问题的原因。看看其他的选择。有吗?或者我应该简单地迁移到Dash吗?就像我说的,你可以使用浏览器工具包&这应该会带来“一些”旧功能,但我建议迁移到Dash,因为它目前是受支持的。