Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PHPUnit tests from directory with custom framework

For our project I have created a framework on top of the PHPUnit framework which helps us in some of the common tasks in writing unit tests.

This custom framework inherits from PHPUnit_Framework_TestCase and then modifies the mySetup() and adds bunch of useful functions for our code.

<?php

class OurUnitTestFramework extends PHPUnit_Framework_TestCase {

    public $dbMock;
    protected function mySetup (..) { ... }
    protected function testHelper () { ... }

}
?>

Now in our test code we just extend OurUnitTestFramework and then write the tests.

<?php 
require_once ("OurUnitTestFramework");
class DatabaseConnectionTest extends OurUnitTestFramework {
     parent::setUp (..) { ... }
     public function testSomeThing () { ... }
     public function testSomeOtherThing () { ... }

}
?>

Till now we were running all the unit tests through Jenkins and it still is running fine but now when we try to run the tests in a folder it fails. All the tests inside the folder/sub-folder runs successfully but there is one failure:

[sumit@dev model]$ phpunit database
PHPUnit 3.5.14 by Sebastian Bergmann.

F........

Time: 0 seconds, Memory: 10.50Mb

There was 1 failure:

1) Warning
No tests found in class "OurUnitTestFramework".


FAILURES!
Tests: 9, Assertions: 30, Failures: 1.

I have a directory database which has sub directories and all the tests passes from that folder and its subfolder but I get failure from OurUnitTestFramework saying there is no tests found in this custom framework. So I am not able to understand why phpunit is running unit tests on the file which is included/extended in the test file?

We can simply choose to ignore this one error but I wanted to know if okay to leave like this or is there something that I need to configure to make it pass.

Thanks

like image 719
Sumitk Avatar asked Jul 25 '26 12:07

Sumitk


1 Answers

Make 'OurUnitTestFramework' an abstract class.

like image 106
Evert Avatar answered Jul 28 '26 02:07

Evert