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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With