[nycphp-talk] Unit Testing with PHP: PHPUnit and Selenium
Anirudhsinh Zala
arzala at gmail.com
Wed Dec 28 01:50:56 EST 2011
On Wednesday 28 December 2011 00:08:10 Nelly Yusupova wrote:
> Hello Everyone,
>
> We are setting up an environment for running unit tests for our PHP
> application.
>
> We installed PHPUnit testing framework and were thinking of using it with
> Selenium. There is lots of examples online of people who used PHPUnit &
> Selenium together but I've read that the support of PHP in Selenium is
> deprecated and I¹m wondering if this is the right way to go.
>
> I would love to hear your experiences with PHP unit testing frameworks and
> if you are using unit testing, what does your set up look like.
I suggest, from my experience, not to use Selenium and tools etc. to make/run unit tests because selenium is primarily to run funcitonal tests which are very different from unit tests. For unit tests, you would mostly use PHPUnit itself. So for now for unit testing of PHP bases code, PHPUnit is de-facto software. There are others but not as widely used as PHPUnit.
Please find some generic guidelines below:
1. You should maintain hierarchy of classes as well as their equivalent test cases in same way. So for example if class file is grouped as lib/Validate/Numeric.php then it's corresponding test case should also be grouped as test/unit/Validate/NumericTest.php. Moreover name of test case class should also follow name of class that is to be tested as shown below:
Class to be tested: Validate_Numeric
Test case class: Validate_NumericTest
Please check how frameworks like Zend etc. does it.
2. It is recommended to write test cases for logical part only i.e static code/data need not to get tested. For complex test cases such as for Database, Mailing etc., it may require certain environmental settings.
3. Fixtures (such as images, data files etc.) of test cases should be kept in same folder where test case/s reside/s. However larger contents can be put in separate folder.
4. All test cases are to be run from project's base directory only. This is necessary because it is required to generate agile documentation of unit tests cases and their classes.
5: All test cases should also be grouped into suite to run all of them at a time.
My advice is not to use Selenium etc. for unit testing at all as Selenium is best suited for functional tests only.
Thanks
@anirudh
>
> Thank you in advance for your responses.
>
> Sincerely,
> Nelly Yusupova
> Digitalwoman.com
> nelly at digitalwoman.com
> 917 603-9226 (phone)
> URL: http://www.digitalwoman.com
> Blog: http://www.webgrrls.com/blog/
> Twitter: http://twitter.com/DigitalWoman
>
>
More information about the talk
mailing list