Unit Testing & Mock Objects |
[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.
[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.
[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
[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/1...velopment/
[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. :-(
[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?
[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.
[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...
[eluser]TheFuzzy0ne[/eluser]
Perhaps this URL may help: http://www.lastcraft.com/mock_objects_documentation.php
[eluser]Aniket[/eluser]
no problem... :-) Thanks for giving an attempt. Will try to find a solution...hope to get it soon. Thanks again |
Welcome Guest, Not a member yet? Register Sign In |