![]() |
Unit Testing & Mock Objects - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Unit Testing & Mock Objects (/showthread.php?tid=16079) Pages:
1
2
|
Unit Testing & Mock Objects - El Forum - 02-23-2009 [eluser]Aniket[/eluser] Hi all, Has anybody tried writing a test case in CI using mock objects ??. I have integrated simpletest with CI thanks to the CI wiki but the examples provided aren't sufficeint enough coz they are not dealing with controllers. If i want to test my controller den should i directly create a mock object of my controller or is there any other approach. Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]Aniket[/eluser] It seems nobody has tried it out yet...anyways i am able to test my model using SimpleTest but without using Mock object. Will try to find a way to do it with mock object too...and will post soon. Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]Aniket[/eluser] The way CI loads itself makes it difficult to create a mock object for database.. :-(. But if anybody finds a better way post on this thread Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]TheFuzzy0ne[/eluser] Apparently, your answer can be found in chapter 8 of CodeIgniter for Rapid PHP Application Development. http://blogs.linux.ie/kenguest/2008/04/10/book-review-codeigniter-for-rapid-php-application-development/ Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]Aniket[/eluser] hi again, i read the book but it just mentions about mock objects for database but nothing relevant is provided....it talks about test data and nothing else. I searched a lot but till now no break through. :-( Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]TheFuzzy0ne[/eluser] Can you post an example of what you have so far? I was in to TDD many years ago. I've probably forgotten most of it, but who knows? Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]Aniket[/eluser] i am developing a demo forum application. I have following models : ForumTopic, ForumComment.... I want to unit test ForumComment. Following is my ForumComment model: Code: <?php Following is my unit test case which i was able to create ..its my first unit test case. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); But i have auto loaded the database for the test case to execute. But i want to mock my database but i cant figure out the way to create one. Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]TheFuzzy0ne[/eluser] I'm so confused. That may as well be written in Russian... I guess I can't remember as much as I'd hoped. Sorry... Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]TheFuzzy0ne[/eluser] Perhaps this URL may help: http://www.lastcraft.com/mock_objects_documentation.php Unit Testing & Mock Objects - El Forum - 02-24-2009 [eluser]Aniket[/eluser] no problem... :-) Thanks for giving an attempt. Will try to find a solution...hope to get it soon. Thanks again |