CakePHP/Jenkins/Phing - Run all unit tests
Asked Answered
C

2

9

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.

Capillarity answered 6/7, 2012 at 14:32 Comment(1)
It looks like there will be built-in support for this (again?) in CakePHP 2.5: github.com/cakephp/cakephp/pull/2655Uncommercial
C
12

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.

Capillarity answered 9/7, 2012 at 16:35 Comment(2)
If you get here through Google, you add all tests (not just those from Model dir) like this: $suite->addTestDirectoryRecursive(TESTS . 'Case');Falco
i think more description is required ,i am not understanding the solution here, am i missing somethingAlways
W
0

Try cake test app all. I can't confirm this makes the difference just now, but I've pulled this out of a phing build file where I'm doing the same thing as you so it should be good.

Wipe answered 9/7, 2012 at 1:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.