簡體   English   中英

無法在測試文件夾外運行 PHPUnit

[英]Unable to run PHPUnit outside of tests folder

所以我有一個 CodeIgniter 項目,我正在嘗試使用 PHPUnit。 我的目錄看起來像

application
node_modules
Gruntfile.js
scripts
vendor
tests
    PostTest.php
    phpunit.phar
    bootstrap.php
    phpunit.xml
composer.json
package.json

當我在測試文件夾中時,我可以執行“phpunit”。 或“php phpunit.phar”。 在 PostTest.php 中運行測試並且工作正常,但是當我在根文件夾中並嘗試執行“phpunit測試”時,我收到錯誤:

ERROR: Not Found

    The controller/method pair you requested was not found.

測試后.php

<?php
class PostTest extends PHPUnit_Framework_TestCase {
      private $CI;

      public function setUp() {
          $this->CI = &get_instance();
      }

      public function testNotes() {
        $this->CI->load->model('class');
        $students = $this->CI->class->getStudents('11');
        $this->assertEquals(3, count($students->result_array()));
      }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
    <phpunit bootstrap="bootstrap.php"
             colors="true"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             processIsolation="false"
             stopOnFailure="false"
             syntaxCheck="false"
             verbose="true">
    </phpunit>

有沒有人知道為什么我會收到這個錯誤?

Phpunit 在當前目錄中查找 phpunit.xml,然后進入目錄以查找測試文件。 所以把這個文件移動到 webroot,你應該被排序。 或者,您可以在 phpunit.xml 中指定要在其中運行的測試目錄並將其保留在原處,然后添加類似(未經測試)的內容以使其在 webroot 中包含測試:

<testsuites>
    <testsuite name="My Test Suite">
        <directory suffix="Test.php">../</directory>
    </testsuite>
</testsuites>

https://phpunit.de/manual/current/en/appendixes.configuration.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM