Unit testing CI Applications |
[eluser]Adrian Walls[/eluser]
Hi, I am currently trying to implement a unit testing framework for an application I have written using CI. I have read through various posts on this forum and others about ways to implement this and decided to write my unit tests using CIUnit. However I have run into a few issues and was hoping someone somewhere had managed to set this up successfully and could possibly shed some light on my problems. Firstly I am trying to test the controllers in my app. However in my controllers there are session variables are being checked, such as if a user is logged in. This causes the CIUnit test to fall over as these session variables have not been initialised. Is there a way I can set the session variables via the CIUnit test code so that they are initialised when called via the test run from the command line? Secondly if I try to run tests against my model code I keep getting a DB error when running the tests. The error on the command line says: Sorry, the name of your test database must end on '_test'. This prevents deleting important data by accident. And the CI log file shows the following error: ERROR - 2008-08-22 18:22:22 --> Severity: Notice --> Undefined property: Controller::$db C:\Sites\dev\rhff\system\application\libraries\fooStack\Fixture.php 32 ERROR - 2008-08-22 18:22:22 --> Severity: Notice --> Trying to get property of non-object C:\Sites\dev\rhff\system\application\libraries\fooStack\Fixture.php 32 The line in question in Fixtures.php is: Code: $db_name_len = strlen($this->CI->db->database); And it appears that this is empty??? The config/database.php file looks like: Code: $env_used = 'default'; //where default would be the name of your development setting I appreciate that there might be a lot of information in this one post covering a few different issues but I thought I'd just throw all the cards out on the table for now :-). If it generates a lot of response I'll break it up into separate posts but for now I'll keep it condensed into this post. I look forward to hearing other people’s experiences with implementing CIUnit or any other unit testing frameworks. Cheers.
[eluser]Adrian Walls[/eluser]
I have been looking at this back and forward again and have moved on slightly. I have managed to sort the database issue out. I needed to set-up a completely new database group in my database.php file which did the trick. However when I try to run the generate fixtures script I get an error message: Unable to load the requested file: helpers/cl_helper.php I cannot find this file anywhere in either CI, phpunit or CIUnit. I am not sure which project it forms part of (if any of these). Does anyone have any ideas? Thanks.
[eluser]rafsoaken[/eluser]
Thanks Wallzy for bringing this up (yes, there is a 2nd database setting needed, ending on '_test', and the the CI_helper.php file is no longer needed with the new release) - This is fixed in the new version of CIUnit, get it as usual here: CIUnit v0.12. There is a public mercurial repository now, where you can also download the bleeding edge version: bitbucket CIUnit repository Happy testing Clemens |
Welcome Guest, Not a member yet? Register Sign In |