Re: Re: Unit Testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You are right, when doing unit tests you only want to test the functionality
of the current class and so if there are errors its easier to track down
which class is causing the problem.

I personally use an api called SimpleTest for my php testing and what you
can do with this is create Mock objects for substituting the objects that
you dont need to test. A Mock object is basically a clone of a classes
structure which then allows you to do stuff like set the return values of
each function or perform tests on the parameters passed to each function.
Ive not used PHPUnit so im not sure if you can do something similar.


On Mon, Apr 27, 2009 at 7:20 PM, Philip Thompson <philthathril@xxxxxxxxx>wrote:

> On Apr 27, 2009, at 11:38 AM, Simon wrote:
>
>  As a programmer, i always test what I'm coding as i code it (mostly to
>> make sure i dont include typos), but i feel it is best to make proper
>> testing once the component is ready and working fine.  If your project
>> is large, it might be a good idea to break it in several 'modules' or
>> section if possible and treat each of them as separate projects
>> (testing would be done on a module once this one is ready).
>>
>> You may be interested in looking for information on the net on 'IT
>> project management' which usually describe when is the best time to
>> test according to a certain structure...
>>
>> Simon
>>
>> On Mon, Apr 27, 2009 at 12:16 PM, Nathan Rixham <nrixham@xxxxxxxxx>
>> wrote:
>>
>>> Philip Thompson wrote:
>>>
>>>>
>>>> Hi. I did some searching in the archives, but didn't quite find what I
>>>> was
>>>> looking for. Maybe a few of you can assist me...
>>>>
>>>> We have an application that's currently in production, but we're
>>>> constantly modifying/upgrading it. We did not do unit testing early on
>>>> because of the lack of time. Now that some time has opened up, we're
>>>> considering unit testing. My question is..... is it reasonable to start
>>>> unit
>>>> testing at this point in time with the application mostly built? Besides
>>>> being really time-consuming, what are the pitfalls of starting unit
>>>> testing
>>>> at this stage?
>>>>
>>>> Thanks in advance,
>>>> ~Philip
>>>>
>>>
>>> maybe a useless answer, but, no pitfalls - just do it - I'm always
>>> surprised
>>> by my unit test results, its invaluable and it's never too late to start.
>>>
>>> just think about the next years worth of bugs found by the client not
>>> being
>>> there!
>>>
>>
> A question I have about unit testing. The point is to test individual
> "units"... correct? So, let's say I have this core class which creates
> instances of other classes. Well, if I only want test the core class, I
> don't want to instantiate the other classes... correct? Example:
>
> <?php
> // Core.php
> require ('Class1.php');
> require ('Class2.php');
>
> class Core {
>    public function __construct () {
>        $this->class1 = new Class1 ($this);
>        $this->class2 = new Class2 ($this);
>    }
> }
>
> // CoreTest.php
> require ('../PHPUnit/Framework.php');
> require ('../includes/Core.php');
>
> class CoreTest extends PHPUnit_Framework_TestCase {
>    protected function setUp () {
>        $this->core = new Core();
>    }
> }
> ?>
>
> So, here, Class1 and Class2 will be instantiated. However, I don't really
> care for them to be so that I can test all the methods in the core class. Is
> this a perfect example of how the original design of the core class is not
> conducive to implementing unit tests? Without rewriting the core class, is
> there a way to test this?
>
> Thanks,
> ~Philip
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux