Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP/Jenkins/Phing - Run all unit tests

I'm in the middle of my first ever stab at setting up Jenkins to build and run unit tests /code coverage with my CakePHP project. So far I have successfully got Jenkins fetching and building automatically from my BitBucket repository - a small victory in itself.

Next thing I want to happen is for the unit tests to run and code coverage reports to be populated.

Here is my build.xml, which is being executed in Jenkins with the (only) build command phing -f $WORKSPACE/build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Consumer Love" default="phpunit">
    <target name="phpunit">
        <exec command="cake test app --coverage-clover logs/reports/clover.xml"></exec>
    </target>
</project>

I think the issue is that when you run cake test app it asks for a prompt of which specific tests you want to run, I have been unable to figure out a method to run all of my CakePHP app unit tests.

like image 685
Dunhamzzz Avatar asked Jul 06 '12 14:07

Dunhamzzz


1 Answers

The solution was to create a custom CakePHP Test suite which adds specific files/directories to be tested, then run that suite with the command cake test app AllTests.

For example, here is my Test/Case/AllTests.php:

/*
 * Custom test suite to execute all tests
 */

class AllTestsTest extends PHPUnit_Framework_TestSuite {

    public static function suite() {

        $path = APP . 'Test' . DS . 'Case' . DS;

        $suite = new CakeTestSuite('All tests');
        $suite->addTestDirectory($path . 'Model' . DS);
        return $suite;

    }

}

This testsuite simply adds the Models directory to the testing environment, so all my model tests now get executed. As you can see it can be extended to run more/all tests as seen fit.

like image 97
Dunhamzzz Avatar answered Oct 31 '22 06:10

Dunhamzzz