phpunit throws Uncaught exception 'PHPUnit_Framework_Exception

后端 未结 3 1452
梦谈多话
梦谈多话 2021-01-12 20:35

I have a Zend Framework project, and want to using unit testing to test it.

In tests folder, I have the phpunit.xml as following;



        
相关标签:
3条回答
  • 2021-01-12 20:44

    I was having the same problem with the same setup. From what I understand, more recent versions of PHPUnit require at least one actual test to run properly. After creating a simple test, it worked.

    myProject/tests/application/DemoTest.php

    <?php
    class DemoTest extends ControllerTestCase
    {
        public function setUp() {
            parent::setUp();
        }
    
        public function testCanDoUnitTest() {
            $this->assertTrue(true);
        }
    }
    
    0 讨论(0)
  • 2021-01-12 20:58

    I noticed that you're not using the <testsuites> which contains multiple occurences of <testsuite>.

    Here is my phpunit.xml which works fine for Zend Framework projects:

    <testsuites>
      <testsuite name="UnitTests">
        <directory>./library</directory>
      </testsuite>
      <testsuite name="ApplicationTests">
        <directory>./application</directory>
      </testsuite>
    </testsuites>
    
    0 讨论(0)
  • 2021-01-12 20:59

    Youll notice its throwing the exception because its looking for a file named the same as the name you provided for your test suite. You need to actually write a test suite and then supply the name of that test suite to your config: http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

    0 讨论(0)
提交回复
热议问题