Unit Test Generator For Basic Model Crud Operations.
UnitTestYiis auto-generates unit tests for basic Create, Read, Update and Delete actions on a given Model.
Requirements ¶
Yii 1.4 or above.
You must have a fixture for the given Model you wish to generate a test on.
Installation ¶
- Place the `CrudUnit' directory into your extensions directory
- Place the file `CreateUnitTestCommand.php' into your 'commands/shell' directory.
- In your `config/test.php' add the import statement bellow
'import'=>array(
'ext.CrudUnit.*'
),
Usage ¶
- Open your terminal and enter yiic shell
- Type createunittest
- You will be prompted to enter your Model name
(example: `User').
- Enter the model name and hit enter.
- You will be prompted to enter the name of your fixture file without the
.php'
(example:users').
- Enter the fixture file name and hit enter.
- You will be prompted to enter your fixture key prefix
(Example `user_' as in ('user_1'=>array('id'=>1, etc..), user_2=>array('id'=>2, ...), ...).
- Enter the fixture key prefix and hit enter
- Yo will be asked "Are there attributes of '$modelName' that are contained in
fixture '$fixtureName' modified by beforeSave or other action(s)? [Yes|No]:"
- Enter 'yes' or 'no' and hit enter.
- Run your tests!
Update 1.3 ¶
NOW SUPPORTS MULTI-COLUMN-PRIMARY-KEYS
Update ¶
- Added more detailed messages on test failures
- Added a status flag for turning off data consistency checks on inserts and
updates. Useful when data is modified by methods like beforeSave().
- Everyone should download the latest version.
Resources ¶
Total 4 comments
I tried to implement this on wamp env. .. c:/wamp/www/yiidemo/yiic shell createunittest but it give error as , " createunittest doesnot exist or is not an entry script file"....
I get a fatal error running test, class 'CrudBase' not found... though I well wrote the import array in my config/test.php... Did I miss something ?
update:
Ok it's because when you run your test, you need to be in protected/test directory... you cannot launch your tests from protected/ for example... weird...
Great suggestion.
I have updated UnitTestYiis to include appropriate assertion messages.
Thanks redguy!
Please provide more informative messages to your assertions. You can pass them as parameter to assert functions like this:
and they will be used when such assertion fails providing more info about what was tested and failed...
Leave a comment
Please login to leave your comment.