简体   繁体   English

Laravel和phpunit-无法达到测试

[英]Laravel and phpunit - can't reach tests

I'm starting with tests in Laravel and now i can't reach my tests using phpunit. 我从Laravel中的测试开始,现在我无法使用phpunit进行测试。

The version of Laravel i'm using is 5.0. 我正在使用的Laravel版本是5.0。

OS is centos7 with php 5.6. 操作系统是带有php 5.6的centos7。

So, the first code i wrote is a duplicate of a existent function in the ExampleTest.php file, stored into "tests" folder, like this: 因此,我编写的第一个代码是ExampleTest.php文件中现有功能的副本,存储在“ tests”文件夹中,如下所示:

 <?php class ExampleTest extends TestCase { /** * A basic functional test example. * * @return void */ public function testBasicExample() { //1 - verificando se a home devolve codigo 200 $response = $this->call('GET', '/'); $this->assertEquals(200, $response->getStatusCode()); } public function testBasicExample2() { //1 - verificando se a home devolve codigo 200 $response = $this->call('GET', '/'); $this->assertEquals(200, $response->getStatusCode()); } } 

This code is only for learning purposes and the goal here is make phpunit run both functions testBasicExample and testBasicExample2. 这段代码仅用于学习目的,此处的目标是使phpunit同时运行testBasicExample和testBasicExample2函数。

Te next step is running phpunit. 下一步是运行phpunit。 In my case, i had to go to the vendor/phpunit directory and run command "php phpunit". 就我而言,我必须转到vendor / phpunit目录并运行命令“ php phpunit”。 Then, the command returned an error: Laravel 5 Failed opening required bootstrap/../vendor/autoload.php 然后,命令返回错误: Laravel 5无法打开所需的bootstrap /../ vendor / autoload.php

So, i followed the best answer and i run "composer update" into terminal. 因此,我遵循最佳答案,并在终端中运行“ composer update”。

Ok, now i can run "php phpunit", but it run other tests and i can't see my exampletest return. 好的,现在我可以运行“ php phpunit”,但是它可以运行其他测试,而我看不到exampletest返回。

在此处输入图片说明

If some more data is needed, please just ask. 如果需要更多数据,请询问。 Any help is apreciated. 任何帮助都非常感谢。

Thanks in advance. 提前致谢。

You should run the binary from your project root: 您应该从项目根目录运行二进制文件:

cd /path/to/project/root
./vendor/bin/phpunit

This should automatically pick up the laravel included phpunit.xml configuration. 这应该会自动选择laravel包含的phpunit.xml配置。 If it does not work you can try running it as : 如果它不起作用,您可以尝试以以下方式运行它:

cd /path/to/project/root
./vendor/bin/phpunit --configuration /path/to/project/root/phpunit.xml

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

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