2017-10-11 114 views
0

我得到這個警告,當我在命令行中運行的PHPUnit:PHPUnit的6.4.1沒有測試執行

PHPUnit 5.1.3 by Sebastian Bergmann and contributors. 

Time: 114 ms, Memory: 4.00MB 

No tests executed! 

這裏是我的框架文件夾結構:

. 
├── App 
├── CHANGELOG 
├── composer.json 
├── composer.lock 
├── Config 
├── Database 
├── local.env.php 
├── phpunit.xml 
├── public 
├── README.md 
├── robot.txt 
├── silver 
├── Storage 
├── System 
├── Tests 
└── vendor 

測試目錄:

Tests 
└── Unit 
    └── ControllerTest.php 

phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit backupGlobals="false" 
     backupStaticAttributes="false" 
     bootstrap="vendor/autoload.php" 
     colors="true" 
     convertErrorsToExceptions="true" 
     convertNoticesToExceptions="true" 
     convertWarningsToExceptions="true" 
     processIsolation="false" 
     stopOnFailure="false"> 
    <testsuites> 
     <testsuite name="Unit"> 
      <directory suffix="Test.php">./Tests/Unit</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

composer.json文件:

"autoload-dev": { 
    "psr-4": { 
     "Tests\\": "Tests/" 
    } 
} 

controllerTest類:

<?php 

namespace Tests\Unit; 

use \PHPUnit\Framework\TestCase; 


class ControllerTest extends TestCase 
{ 
    /** @test */ 
    public function testFirstMethod() 
    { 
     $num = 20; 

     $this->assertEquals(22, $num); 
    } 
} 

任何建議或幫助將是非常讚賞的感謝。

+0

它肯定適合我。我使用phpunit 5.5.7。 – akond

+1

標題說PHPUnit的'6.4.1'和你的命令行說'5.1.3'?!? – bish

+0

@bish是啊你是正確的供應商版本是6.4.1,而phpunit CLI版本是5.1.3我不知道這些應該是相同的,因爲在Linux上當你apt-get安裝phpunit你默認得到5.1.3! –

回答

1

看起來您已經將PHPUnit的不同安裝混淆了。

例如,您可能已經使用Composer安裝PHPUnit,並將Composer生成的自動加載器配置爲PHPUnit的引導腳本,但是然後您使用vendor/bin/phpunit以外的可執行文件調用PHPUnit。

+0

非常感謝你塞巴斯蒂安!來自PHPUnit創始人的一個很好的答案我已經解決了,非常感謝你! –